I have a C++ app which uses a particular XML config. This config has recursive nodes. For example, SubStrategy
can have Strategy
node which in turn can have another SubStrategy
node.
<?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>
I have got schema for same but my app is crashing while loading this. If I look at backtrace in gdb, I can see it's dying validating recursive schema. Below is 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 backtrace
#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
I am using a 3rd party wrapper for XML parser which internally used XERCES-C++ version 3.1.1. My query is if any one knows how to use recursion in schema with XERCES-C OR if this is known issue with XERCES? Couldn't find any relevant info on apache page.
There is nothing wrong with your XML or your XSD. Your XML is valid against your XSD, in fact.
Xerces can handle recursive XML Schemas just fine.
You or the "wrapper" you're using are probably improperly re-invoking parsing from within a parsing callback. This is not Xerces' fault (nor the XML's nor the XSD's fault); it's a problem of how Xerces is being used.