2016-03-28 37 views
1

我有一個使用特定XML配置的C++應用程序。這個配置有遞歸節點。例如,SubStrategy可以有Strategy節點,而節點又可以有另一個SubStrategy節點。使用Xerces-C++解析遞歸XML模式(XSD)時發生Seg Fault

<?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中查看回溯,我可以看到它正在驗證遞歸模式。 下面是Scehma

<?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++版本3.1.1 XML解析器第三方包裝。我的查詢是否有人知道如何使用XERCES-C在架構中使用遞歸,或者如果這是XERCES的已知問題?在apache頁面找不到任何相關信息。

回答

1

您的XML或您的XSD沒有任何問題。事實上,您的XML對您的XSD有效。

Xerces可以很好地處理遞歸XML模式。

您或您正在使用的「包裝器」可能不正確地重新調用解析回調中的解析。這不是Xerces的錯(也不是XSD的錯誤)。這是Xerces如何使用的問題。