XercesDOMParser and XIncludes

徘徊边缘 提交于 2019-12-10 18:16:02

问题


I am attempting to get xincludes working in an existing system that uses a XercesDOMParser in xercesc to parse incoming xml from a client. I am working with Apache Xercesc v3.0.1, and the incoming XML, read from an input stream, is:

<?xml version="1.0" encoding="UTF-8"?>
<VisionServer xmlns:xi="http://www.w3.org/2001/XInclude">
    <CompositeObject>
 <xi:include href="testguioutput.xml" />

while testguioutput.xml contains

<?xml version="1.0" encoding="UTF-8"?>
<GUIOutput>
    <Input>Input</Input>
    <Title>IDC2_1</Title>
</GUIOutput>

The existing code uses a wrapper around a XercesDOMParser to parse the XML as it comes in, and after using setDoNamespaces and setDoXInclude to true, it is attempting to parse the XInclude, but I get a persistent "Fatal: include failed and no fallback element found in document '{0}'" error, no matter where in the directory structure I put testguioutput.xml.

I am working under visualstudio 2008, my working directory is default, and running out of /project/debug, but the include fails whether the target file is in /project/ or /project/debug/.


回答1:


I was able to expand the xinclude tags using the XInclude.exe sample application that is included with the Xerces application. To do this, I created two files using your files above:

test1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<VisionServer xmlns:xi="http://www.w3.org/2001/XInclude">
  <CompositeObject>
    <xi:include href="test2.xml"/>
  </CompositeObject>
</VisionServer>

test2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<GUIOutput>
  <Input>Input</Input>
  <Title>IDC2_1</Title>
</GUIOutput>

At the command line I executed:

"XInclude.exe test1.xml test1_expanded.xml" without quotes.

The resulting test1_expanded.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<VisionServer xmlns="" xmlns:xi="http://www.w3.org/2001/XInclude">
  <CompositeObject>
    <GUIOutput xml:base="test2.xml">
      <Input>Input</Input>
      <Title>IDC2_1</Title>
    </GUIOutput>
  </CompositeObject>
</VisionServer>


来源:https://stackoverflow.com/questions/2155844/xercesdomparser-and-xincludes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!