codesynthesis not parsing my xml file

為{幸葍}努か 提交于 2019-12-11 09:58:41

问题


I am using codesynthesis to generate classes which represent my xsd file. The xml file has been validated against the schema file using an online validation program and it seems to be fine. However upon running my program which simply reads the xml and attempts to create the structures representing the xml file i get exceptions for every element such as : error: attribute 'dburl' is not declared for element 'quantoptions', error: no declaration found for element 'option' and error: no declaration found for element 'symbol'. Can someone please advise as to why this is happening?

This is the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Document created with online XML Editor http://xmlgrid.net 2013/09/08 2:17:41  -->
   <quantoptions dburl="test attribute">
         <option>
               <symbol>test string</symbol>
               <dateselection enddate="2002-09-24" startdate="2002-09-24"></dateselection>
         </option>
         <option>
               <symbol>test string</symbol>
               <dateselection enddate="2002-09-24" startdate="2002-09-24"></dateselection>
               <blackscholes>false</blackscholes>
               <volatility>true</volatility>
         </option>
   </quantoptions>

this is the xsd file:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                <xs:element name="quantoptions">
                                <xs:complexType>
                                                <xs:sequence>
                                                                <xs:element maxOccurs="unbounded" minOccurs="1" name="option">
                                                                            <xs:complexType>
                                                                                                <xs:sequence maxOccurs="1" minOccurs="1">
                                                                                                                <xs:element maxOccurs="1" minOccurs="1" name="symbol" type="xs:string"/>
                                                                                                            <xs:element maxOccurs="1" minOccurs="1" name="dateselection">
                                                                                                                            <xs:complexType>
                                                                                                                                            <xs:attribute name="enddate" type="xs:date" use="required"/>
                                                                                                                                            <xs:attribute name="startdate" type="xs:date" use="required"/>
                                                                                                                            </xs:complexType>
                                                                                                            </xs:element>
                                                                                                            <xs:choice maxOccurs="unbounded" minOccurs="0">
                                                                                                                            <xs:element maxOccurs="1" minOccurs="1" name="blackscholes" type="xs:boolean"/>
                                                                                                                            <xs:element maxOccurs="1" minOccurs="1" name="volatility" type="xs:boolean"/>
                                                                                                            </xs:choice>
                                                                                            </xs:sequence>
                                                                            </xs:complexType>
                                                            </xs:element>
                                            </xs:sequence>
                                            <xs:attribute name="dburl" type="xs:string" use="required"/>
                            </xs:complexType>
            </xs:element>

and finally here is the code, exception is thrown on this line: std::auto_ptr optionConfig (quantoptions_ (configPath));

    const std::string configPath  = "../config/quantoptions.xml";
    std::auto_ptr<quantoptions> optionConfig (quantoptions_ (configPath));

    optionConfig->dburl();

    for(quantoptions::option_const_iterator i (optionConfig->option().begin()); i != optionConfig->option().end(); ++i)
    {
        std::cout<< i->symbol();
    }

thanks in advance


回答1:


finally fixed the problem, i am not sure if this was documented but although the xml was well formed, code synthesis was looking for the following lines within xml : . so the working xml looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Document created with online XML Editor http://xmlgrid.net 2013/09/08 2:17:41  -->
   <quantoptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd" dburl="test attribute">
         <option>
               <symbol>test string</symbol>
               <dateselection enddate="2002-09-24" startdate="2002-09-24"></dateselection>
         </option>
         <option>
               <symbol>test string</symbol>
               <dateselection enddate="2002-09-24" startdate="2002-09-24"></dateselection>
               <blackscholes>false</blackscholes>
               <volatility>true</volatility>
         </option>
   </quantoptions>


来源:https://stackoverflow.com/questions/18684003/codesynthesis-not-parsing-my-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!