16

Over and over again, people ask questions about SimpleXML (the PHP built-in XML library which is, well, simple), because either:

The problem is that most of these questions have accepted answers with either really bad advice (like mangling the XML with str_replace before parsing it), or unnecessarily specific examples, so it's hard to find a good duplicate target.

For the record, there are two ways to use SimpleXML with namespaces: the ->children(), and ->attributes() methods to access the elements directly; or ->registerXpathNamespace() if you want to use XPath.

I'd like to create a (Community Wiki) canonical Q&A for this, but don't want to go around dupe-hammering dozens of questions if people disagree, or think there is already a good target somewhere.

1 Answer 1

3

I have started building the question and answer here: Reference - how do I handle namespaces (tags and attributes with colon in) in SimpleXML?

To do (help welcome...):

  • Add examples using default namespace, and accessing un-prefixed attributes (not the same thing!)
  • Add an extra section / answer on using XPath and registerXpathNamespace
  • Add an extra section / answer on creating / editing namespaced XML
  • Maybe make it less wordy (a personal weakness).
  • Start closing duplicates against it, copy in good bits from other people's answers, and notify them with a comment.
  • Figure out how to mark the question as Community Wiki as well as the answer, as I've seen on other Reference questions. (Or should I just enjoy the reputation boost?)

As I say above, there are potentially dozens of duplicates for this, so I want to proceed slowly and make sure I don't tread on any toes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .