我想了解一些指导性的部分,我有点失去了以下解释的逻辑:
首先代码:Link
现在指南:
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.
这是代码给出之前的部分,现在这是在代码之后给出的部分:
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.
问题:
问题是我不认为我理解作者,如果有人请用另一个词解释这段代码,我会在代码中指出我的逻辑无法理解的弱点:
标签(spec:name)//在XML代码中。
$ sxi-> registerXPathNamespace('spec','http://www.exampe.org/species-title'); //此方法和2个参数。
$ result = $ sxi-> xpath('// spec:name'); //带参数的此方法。
$ sxi-> getDocNamespaces('animal')//在foreach循环中。
如果有人可以专注于我提到的那些部分,并尝试换一句话,谢谢大家,祝你有美好的一天。