Php, Spl, SimpleXMLIterator

Flitmetebob

New Member
I am trying to understand some guide part, I kind of really lost the logic at the following explanation:First The Code:LinkNow the guide:\[quote\] A problem arises in XML when two documents may have similar names. If we had the xml document of animals, and another of animal owners, a conflict may arise in the name node. Each of the animals, and owners would have a name node and a method is required to distinguish between them. The SimpleXMLIterator provides several methods for the management of namespaces. These include as listed in the top of the this chapter. The script below shows a small change to the xml string that has been used and demonstrates the use of namespaces and how to utilize them within the SimpleXMLIterator.\[/quote\]This was the part coming before the code is given, Now this is the part given after the code:\[quote\] In the script above we have declared a namespace in our root as Also not the addtion to the XML of a second name node. This is prefixed by the spec: prefix to identify the namespace and not confuse it with the regular animal names. The use of the SimpleXMLIterator::registerXPathNamespace() method ensures the document namespace prefixing is sane. To get the namespaces the SimpleXMLIterator::getDocNamespaces() method is used to get the names of all namespaces declared within the document. The SimpleXMLIterator::getNamespaces() method could also have been used. The SimpleXMLIterator::getDocNamespaces() method only gets those namespaces that are actually declared within the document itself.\[/quote\]The problem:The problem is that i dont think i understand right the author, If some one please can explain this code with another words, I will name weak spots at the code my logic failed to understand:
  • The Tag (spec:name) // At the XML code.
  • $sxi-> registerXPathNamespace('spec', 'http://www.exampe.org/species-title'); // This method and the 2 parameters.
  • $result = $sxi->xpath('//spec:name'); // This method with the parameter.
  • $sxi->getDocNamespaces('animal') // At the foreach loop.
If can someone please focus on those parts i mentioned and try another words, Thank you all and have a nice day.
 
Back
Top