Re: [xml] how to parse in-memory XML *fragments*



On Mon, Jan 16, 2006 at 06:53:16PM +0100, Christian Parpart wrote:
Hi all,

well, I'm having a in-memory XML fragment like:

    "Hello, <b>World</b>! <i>biba</i>"

and I'd like to write an XPath functions to return the 
tree representation of the above XML fragment.

However, xmlParseMemory *seems* to expect a complete document, 
and not an XML fragment, in fact, the above example
would than have two root element nodes which is not valid.

Though, what I need, is, to parse this string somehow into an 
XPath node-set I can safely return within my XPath function.

But I couldn't find any good hints within the API/sources :(

  What you are asking has no semantic. Is there namespaces in scope ?
What about entities, IDs ? 
  You need a framing document, the best I can suggest is 
    http://xmlsoft.org/html/libxml-parser.html#xmlParseInNodeContext

  note that this isn't formally XML parsing as defined by the spec,
you may hit problems, break semantic, or have allocation troubles if you
don't understand libxml2 well enough. You are somewhat on your own since
it's not really a clean interface, libxml2 is liberal enough to let people
do messy stuff, but at their own risks.

Daniel
 

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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