Question

I have the following XML Document:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:apps=\"http://schemas.google.com/apps/2006\" xmlns:gd=\"http://schemas.google.com/g/2005\">
  <apps:property name=\"memberId\" value=\"Tom\"/>
</atom:entry>

All I'm trying to do is get the apps:property node. However everything I try in LibXML returns nothing.

From reading the LibXML documentation here for LibXML::XML::XPath. I would assume that I don't need to specify the two namespaces since they are defined on the root node.

Here is what I've tried:

@document.find('/apps:property')
@document.find('//apps:property')
@document.find('/atom:entry/apps:property')
@document.find('//atom:entry/apps:property')
@document.find('/property')
@document.find('/atom:entry')
@document.find('//property')
@document.find('/entry')

None of the above return a result with the specified document. I've tried them all with different combinations of the atom and apps namespace definitions as well but it doesn't seem to have an effect.

If anyone could show me what very simple thing I must be missing it would be much appreciated.


It turns out that the problem stems from the document being created dynamically rather than being read from a file.

When I write the document to a file and read it in I can search it. When I create the document, create the root element and add the child programmatically I get nil every time I try to search, oddly enough each works just fine. Do I have to "finalize" or do some other stupid thing to the document somehow before I can search it?

Was it helpful?

Solution

If I explicitly parse the document then I can search it.

Looks like that might be the solution unless it's possible for the parse tree to be generated as the document is built.

Time to look at the code I suppose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top