Re: [xml] Newbie question - Getting Node Content from XPath



On 05 Nov 22:57, Andrew Nelson wrote:
}However, I don't know how to get the content of each of the nodes.   
}For example, given the  full XPath "/PMML/Header" how do I obtain the  
}string "Hello World!"?  I've tried using xmlXPathCastNodeToString, on  
}the "/PMML/Header" Xpath, but also get foo printed out.
}I'm thinking that I may have to use xmlXPathEval, am I heading along  
}the right lines?
}
}I'm sorry if this is a simple question.

On one level it is, but on another it's not - there are many different
APIs available in libxml2 to parse a doc tree. However, assuming you
have an xmlNodePtr available (which you seem to since you have called
xmlGetNodePath, I think) you could call something like xmlNodeGetContent.

I find the tree API the most intuitive to use, however it requires you
have your whole XML document in memory so it isn't the most efficient
for large documents. This variety of different ways to do something is
confusing at first, but have a look at some of the example programs in
the distribution and referred to on the website.

    C

-- 

Callum Gibson @ home




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]