Search code examples
c++xmlxml-parsinglibxml2

Parsing xml with colon using libxml


I am facing a problem when trying to parse an XML file that has "colons".

ex:

<PropertyList:Property>
    <property:Condition Mode="ON" />
    <property:Setting max="128" />
</PropertyList:Property>

While the parsing of files without colons works perfect for me. I am using ibxml library, from xmlsoft. And the first instruction where I realise parsing is not working is when i do

xmlDocPtr doc = xmlParseFile("XMLFile.xml");

That returns NULL.

Thanks!


Solution

  • A colon within element names is not just a regular character -- it defines a XML namespace. A namespace must be declared in order to be used - like:

    <root xmlns:PropertyList='http://www.example.org/schema'>
    

    A probable issue with your document is that it doesn't declare the used namespaces, which results in a parsing error.