【问题标题】:XercesDOMParser and XIncludesXercesDOMParser 和 XIncludes
【发布时间】:2011-01-10 11:33:32
【问题描述】:

我试图让 xincludes 在现有系统中工作,该系统使用 xercesc 中的 XercesDOMParser 来解析来自客户端的传入 xml。我正在使用 Apache Xercesc v3.0.1,从输入流中读取的传入 XML 是:

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

而 testguioutput.xml 包含

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

现有代码使用围绕 XercesDOMParser 的包装器来解析传入的 XML,并且在使用 setDoNamespaces 和 setDoXInclude 为 true 后,它正在尝试解析 XInclude,但我得到一个持久的“致命:包含失败并且没有在文档“{0}”中找到后备元素”错误,无论我将 testguioutput.xml 放在目录结构中的哪个位置。

我在visualstudio 2008下工作,我的工作目录是默认的,并且用完了/project/debug,但是无论目标文件是在/project/还是/project/debug/中,include都会失败。

【问题讨论】:

    标签: c++ xml xerces xinclude


    【解决方案1】:

    我能够使用 Xerces 应用程序中包含的 XInclude.exe 示例应用程序来扩展 xinclude 标记。为此,我使用上面的文件创建了两个文件:

    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>
    

    在我执行的命令行:

    "XInclude.exe test1.xml test1_expanded.xml" 不带引号。

    生成的 test1_expanded.xml 文件:

    <?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>
    

    【讨论】:

    • 我认为问题可能是我没有处理从文件加载 test1.xml,而是从输入流中接收它。这可能意味着它没有加载 test2.xml 的上下文,但我不知道如何解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多