Re: [xml] ignore undefined entity references while parsing?




Yes, I have the  same question. And I read in the Xerces API documentation:


"entities"

true [required] Keep EntityReference and Entity nodes in the document.

false [required] (default) Remove all EntityReference and Entity nodes from
the document, putting the entity expansions directly in their place. Text
nodes are into "normal" form. Only EntityReference nodes to non-defined
entities are kept in the document.

(http://xerces.apache.org/xerces-c/apiDocs-3/classDOMConfiguration.html)


Therefore entity reference nodes to undefined entities should be kept in the
document. But try the next program:


#include <iostream>
using namespace std;

#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/PlatformUtils.hpp>
using namespace xercesc;

namespace {
    bool entity_reference_node_found(DOMNode const* const node)
    {
        if (DOMNode::ENTITY_REFERENCE_NODE == node->getNodeType())
            return true;
        for (DOMNode const* child = node->getFirstChild(); child; child =
child->getNextSibling())
            if (entity_reference_node_found(child))
                return true;
        return false;
    }
}

int main()
{
    XMLPlatformUtils::Initialize();
    {
        XercesDOMParser parser;
        parser.parse("undefined_entity.xml");
        cout << entity_reference_node_found(parser.getDocument()) << '\n';
    }
    XMLPlatformUtils::Terminate();
}


with the next XML file:


<?xml version="1.0"?>
<!DOCTYPE test>
<test>&abcd;</test>


It will print 0. Why?

-- 
View this message in context: 
http://www.nabble.com/ignore-undefined-entity-references-while-parsing--tp15791950p23899285.html
Sent from the Gnome - Lib - Xml - General mailing list archive at Nabble.com.




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