c++ - How to read xsd file where root element is not a named type -


i have xml , xsd file. can read xml using xerces if xsd file has root xml element define named complextype trying figure out how read file if root item in xsd not named type. here files:

the xml file

<?xml version="1.0"?> <x:books xmlns:x="urn:bookstore"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="urn:bookstore books.xsd">     <book id="bk001">       <author>writer</author>       <title>the first book</title>       <genre>fiction</genre>       <price>44.95</price>       <pub_date>2000-10-01</pub_date>       <review>an amazing story of nothing.</review>    </book>     <book id="bk002">       <author>poet</author>       <title>the poet's first poem</title>       <genre>poem</genre>       <price>24.95</price>       <pub_date>2001-10-01</pub_date>       <review>least poetic poems.</review>    </book> </x:books> 

the xsd file:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema"             targetnamespace="urn:bookstore"             xmlns:bks="urn:bookstore">      <xsd:complextype name="bookform">         <xsd:sequence>           <xsd:element name="author"   type="xsd:string"/>           <xsd:element name="title"    type="xsd:string"/>           <xsd:element name="genre"    type="xsd:string"/>           <xsd:element name="price"    type="xsd:float" />           <xsd:element name="pub_date" type="xsd:date" />           <xsd:element name="review"   type="xsd:string"/>         </xsd:sequence>         <xsd:attribute name="id"   type="xsd:string"/>   </xsd:complextype>            <xsd:element name="books">  <!-- not mapped named typed! -->       <xsd:complextype >         <xsd:sequence>           <xsd:element name="book"                        type="bks:bookform"                        minoccurs="0"                        maxoccurs="unbounded"/>           </xsd:sequence>       </xsd:complextype>   </xsd:element> </xsd:schema> 

reading library (reading 2 fields)

#include <iostream> #include "books.h"  using namespace std; using namespace bookstore;  int main(int argc, char *argv[]) {     qcoreapplication a(argc, argv);      try {          // do here since booksform not defined , xsd file         // doesn't map root element of xml?         auto_ptr<booksform> bookbank (books( "books.xml" ));          (booksform::book_const_iterator = (bookbank->book().begin());              != bookbank->book().end();              ++i)         {             cout << "author '" << i->author() << "'' " << endl;             cout << "title '" << i->title() << "'' " << endl;              cout << endl;         }      }     catch (const xml_schema::exception& e)     {       cerr << e << endl;       return 1;     }      return a.exec(); } 

so code works if xsd file in format in post want know how can read xml if xsd file in above format. need in small demo can resolve similar situation in larger , more complex xml file given thing.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -