【问题标题】:Seg Fault while parsing recursive XML Schema (XSD) with Xerces-C++使用 Xerces-C++ 解析递归 XML 模式 (XSD) 时出现 Seg Fault
【发布时间】:2016-03-28 11:30:08
【问题描述】:

我有一个使用特定 XML 配置的 C++ 应用程序。此配置具有递归节点。例如,SubStrategy 可以拥有Strategy 节点,而SubStrategy 节点又可以拥有另一个SubStrategy 节点。

<?xml version="1.0" encoding="UTF-8"?>
<CONF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="rfq.xsd">
        <SubStrategy name="ss1">
                <Strategy>
                        <SubStrategy name="ss2"/>
                </Strategy>
        </SubStrategy>
        <SubStrategy name="ss3">
        </SubStrategy>
</CONF>

我有相同的架构,但我的应用在加载时崩溃了。如果我查看 gdb 中的回溯,我可以看到它正在验证递归模式。 下面是斯凯马

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="SubStrategy">
                <xs:complexType mixed="true">
                        <xs:sequence>
                                <xs:element ref="Strategy" minOccurs="0"/>
                        </xs:sequence>
                        <xs:attribute name="name" type="xs:string" use="required">
                        </xs:attribute>
                </xs:complexType>
        </xs:element>
        <xs:element name="Strategy">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="SubStrategy"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:element name="CONF">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="SubStrategy" maxOccurs="unbounded"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
</xs:schema>

GDB 回溯

#0  0x00007ffff6619ee6 in _int_malloc () from /usr/lib64/libc.so.6
#1  0x00007ffff661c11c in malloc () from /usr/lib64/libc.so.6
#2  0x00007ffff6ed40cd in operator new(unsigned long) () from /usr/lib64/libstdc++.so.6
#3  0x00007ffff6f327e9 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) () from /usr/lib64/libstdc++.so.6
#4  0x00007ffff6f3342b in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) () from /usr/lib64/libstdc++.so.6
#5  0x00007ffff6f334d4 in std::string::reserve(unsigned long) () from /usr/lib64/libstdc++.so.6
#6  0x00007ffff7bcf468 in push_back (__c=<optimized out>, this=<optimized out>)
    at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:858
#7  operator+= (__c=<optimized out>, this=<optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:777
#8  XMLCh_ToString (s=<optimized out>, n="") at /local_dev/cdmi_bmt/../ConfigFile/src/Test.cpp:75
#9  0x00007ffff7bc1877 in ConfigFileImp::processSchemaElem (this=0x6273e0, curElem=...,
    rootname_="CONF.**SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy.SubStrategy.Strategy**.SubStr"...) at /local_dev/cdmi_bmt/configFile.cpp:1591

我正在为内部使用 XERCES-C++ version 3.1.1 的 XML 解析器使用第 3 方包装器。我的问题是是否有人知道如何使用 XERCES-C 在模式中使用递归,或者如果这是 XERCES 的已知问题?在apache 页面上找不到任何相关信息。

【问题讨论】:

    标签: c++ xml xsd xml-parsing xerces-c


    【解决方案1】:

    您的 XML 或 XSD 没有任何问题。事实上,您的 XML 对您的 XSD 有效。

    Xerces 可以很好地处理递归 XML 模式。

    您或您正在使用的“包装器”可能不正确地从解析回调中重新调用解析。这不是 Xerces 的错(也不是 XML 和 XSD 的错);这是如何使用 Xerces 的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2013-07-22
      • 2011-05-31
      • 2018-06-30
      • 1970-01-01
      相关资源
      最近更新 更多