You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Aleksey Dobrunov <ct...@gmail.com> on 2012/03/21 10:03:39 UTC

xercesc c++ external entity resolve

Hi.
I have the following xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo [
  <!ENTITY extern SYSTEM "ext.xml">
]>
<foo>
<foo_info>
<id >2011_0101</id>
<foo_name>foo foo</foo_name>
&extern;
</foo_info>
</foo>

in "ext.xml" I have additional xml tags.
I am using xerces 3.1.1 to parse the xml file using the following function:

xercesc::XercesDOMParser xml_parser;
XmlParserErrorHandler error_handler;
xml_parser.setErrorHandler(&error_handler);
xml_parser.setLoadExternalDTD(false);
xml_parser.setSkipDTDValidation(true);
xml_parser.parse(*current_input_source);
xercesc::DOMDocument *doc = xml_parser.getDocument();
xercesc::DOMElement *root = doc->getDocumentElement();

The problem I have is that the external ENTITY &extern is not resolved, the
parsed file in doc is missing it.

Does anyone have a suggestion on how to make xerces resolve it before
parsing?

Thanks,
Aleksey Dobrunov

Re: xercesc c++ external entity resolve

Posted by Aleksey Dobrunov <ct...@gmail.com>.
I solved the problem.
I thought that elements of the file ext.xml transparently built into the
structure of the document. And this code will process the added items.

for (xercesc::DOMNode *node = elem->getFirstChild(); node != nullptr; node
= node->getNextSibling()) {
  if (node->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
   xercesc::DOMElement *elem = static_cast<xercesc::DOMElement*>(node);
   parseHrcBlockElements(elem);
   }
}

But it turned out that it is necessary to add the following code in the loop
if (node->getNodeType() == xercesc::DOMNode::ENTITY_REFERENCE_NODE ) {
   for (xercesc::DOMNode *sub_node = node->getFirstChild(); sub_node !=
nullptr; sub_node = sub_node->getNextSibling()) {
    xercesc::DOMElement *elem = static_cast<xercesc::DOMElement*>(sub_node);
    parseHrcBlockElements(elem);
   }
}

Thanks,
Aleksey Dobrunov
21 марта 2012 г. 15:03 пользователь Aleksey Dobrunov <ct...@gmail.com>написал:

> Hi.
> I have the following xml file:
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE foo [
>   <!ENTITY extern SYSTEM "ext.xml">
> ]>
> <foo>
> <foo_info>
> <id >2011_0101</id>
> <foo_name>foo foo</foo_name>
> &extern;
> </foo_info>
> </foo>
>
> in "ext.xml" I have additional xml tags.
> I am using xerces 3.1.1 to parse the xml file using the following function:
>
> xercesc::XercesDOMParser xml_parser;
> XmlParserErrorHandler error_handler;
> xml_parser.setErrorHandler(&error_handler);
> xml_parser.setLoadExternalDTD(false);
> xml_parser.setSkipDTDValidation(true);
> xml_parser.parse(*current_input_source);
> xercesc::DOMDocument *doc = xml_parser.getDocument();
> xercesc::DOMElement *root = doc->getDocumentElement();
>
> The problem I have is that the external ENTITY &extern is not resolved,
> the parsed file in doc is missing it.
>
> Does anyone have a suggestion on how to make xerces resolve it before
> parsing?
>
> Thanks,
> Aleksey Dobrunov
>