How to parse a XML string instead of XML doc in c using libxml2 library

forum.test17 picture forum.test17 · Sep 23, 2012 · Viewed 9.6k times · Source

All the examples in libxml2 documentation libxml tutorial are mentioned using external XML files. What if I need to parse a string with XML content in it? Is it really possible in libxml2 C library, or the only solution would be taking the string saving it to the file and sending that file name as argument to the below function. But it would seriously effect the performance.

doc = xmlParseFile(docname);

Are there any inbuilt functions in libxml2 to parse character arrays?

Answer

Joachim Isaksson picture Joachim Isaksson · Sep 23, 2012

You can use xmlParseDoc(), which will take a null terminated string (of xmlChar / unsigned char) and parse it exactly as if it were read from a file using xmlParseFile().