[development] trouble destructing xml

jeff at ayendesigns.com jeff at ayendesigns.com
Fri Mar 25 13:29:15 UTC 2011


I hadn't been concluding I had trouble with simplexml only because dsm() 
didn't show anything, more that dsm reinforced the situation. I was 
referring to what should have been the element in code and coming up 
empty, or with in error, in the case of foreach.

Xpath doesn't work for some reason. I presume there could be something 
unusual with the file layout, since it's full of cpath stuff and I'm 
excerpting it here. It might, in part, have something to do with some of 
the path names being hyphenated. I know php has a problem with that when 
creating an object reference unless it is encased in {}.

Not only does querypath work with the tag name, but it worked too well 
at first. There are, apparently, other such tags elsewhere in the data, 
and I was receiving output for all of them. It turns out you can do some 
wonderful things with querypath. First, I provided further context by using:

         foreach (qp('text.xml', parent-tag-name)->children as $item)

but the problem with that was I received all the children, which 
included the tags I needed, but also others. So, you can also do this:

         foreach (qp('text.xml', 
parent-tag-name)->children(child-tag-name) as $item)

and then only receive the correct tags in the correct concept, such as 
xpath would have done with parent-tag/child-tag had it worked in this case.

Jeff


More information about the development mailing list