[xsd-users] Failing to parse XML document generated with the same
code.
Juan Pablo Perez
juanpablo.perez at gmail.com
Fri Sep 18 15:17:36 EDT 2009
Hi,
I'm working with a simple XSD schema:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="xml_t">
<xsd:sequence>
<xsd:element name="pan" type="xsd:string" />
<xsd:element name="type" type="xsd:string" />
<xsd:element name="amount" type="xsd:float" />
<xsd:element name="respcode" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="msg" type="xml_t"/>
</xsd:schema>
And then, using code I dump a simple XML document:
xml_t xml("PAN", "TYPE", 10.50, 9);
xml_schema::namespace_infomap map;
map[""].name = "";
map[""].schema = "xml1.xsd";
msg(cout, xml, map);
That results on this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xml1.xsd">
<pan>PAN</pan>
<type>TYPE</type>
<amount>10.5</amount>
<respcode>9</respcode>
</msg>
Then I try to load that same XML with the following code in the same
application (2 lines down from before):
try {
auto_ptr<xml_t> xml(msg("xml1.xml"));
}
catch (const xml_schema::exception& e) {
cerr << e << endl; return 1;
}
And when I run the code I get the following errors:
xml1.xml:2:93 error: Unknown element 'msg'
xml1.xml:2:93 error: Attribute 'xmlns' is not declared for element 'msg'
xml1.xml:2:93 error: Attribute '{http://www.w3.org/2000/xmlns/}xsi' is
not declared for element 'msg'
xml1.xml:2:93 error: Attribute
'{http://www.w3.org/2001/XMLSchema}schemaLocation' is not declared for
element 'msg'
xml1.xml:4:8 error: Unknown element 'pan'
xml1.xml:6:9 error: Unknown element 'type'
xml1.xml:8:11 error: Unknown element 'amount'
xml1.xml:10:13 error: Unknown element 'respcode'
I think that the document I created should be parsed back in easily...
What am I doing wrong?
Thanks and regards.
Juan
Any ideas
More information about the xsd-users
mailing list