[xsd-users] How can I put the attribute xsi:type="DataDocument" in the root node?

Roberto Escobar rescobar at datatec-ec.com
Wed Apr 13 12:13:53 EDT 2011


 

Good morning.

 

I have a little problem, I need to parse xml but I cannot do.  I compile
the FpML 4-2 as suggested in
http://wiki.codesynthesis.com/index.php?title=Schemas/FpML&redirect=no

 

Common.options file consists of:

 

--generate-polymorphic

--generate-serialization

 

Fpml.options file consists of:

 

                --root-element FpML

 

--namespace-map http://www.fpml.org/2005/FpML-4-2=FpML_4_2

--namespace-map http://www.w3.org/2000/09/xmldsig#=XMLDSig

 

--polymorphic-type Product

--polymorphic-type Rate

--polymorphic-type Event

--polymorphic-type PricingStructure

--polymorphic-type PricingStructureValuation

--polymorphic-type Portfolio

--polymorphic-type Exercise

--polymorphic-type Asset

--polymorphic-type ChangeEvent

--polymorphic-type CreditEvent

--polymorphic-type DirectionalLeg

--polymorphic-type ReturnSwapLeg

--polymorphic-type QuotableProduct

 

--disable-warning F001

 

The command executed were:

 

1)      xsd cxx-tree --generate-xml-schema --output-dir gen
--options-file common.options xml-schema.xsd

2)      xsd cxx-tree --file-per-type --output-dir gen
--extern-xml-schema xml-schema.xsd --options-file common.options
--options-file fpml.options fpml/fpml-main-4-2.xsd

 

The FpML 4-2 specification was downloaded from link:
http://www.fpml.org/spec/login.php

 

 

My problem is this: The XSD-generated code gives me some functions
"FpML" for parsing an XML file that return a value "Document ", but when
I want to do serialization of object "Document" obtained by functions,
they do not do anything.

 

Code:

 

auto_ptr<Document> doc(FpML("xml_swap.xml"));

 

Document document(*doc);

DataDocument * dataDocument = dynamic_cast<DataDocument*> (&document);

 

xml_schema::namespace_infomap map;

    map[""].name   = "http://www.fpml.org/2005/FpML-4-2";

    map[""].schema = "fpml-main-4-2.xsd";

 

std::ostringstream oss;

    ::FpML_4_2::FpML(oss, *doc, map);

    std::string xml (oss.str ());

 

 

Now,  as I need to manipulate the object "DataDocument" instead
"Document", I do the cast, but this return null.

 

xml file header is as follows:

 

<FpML version="4-2" xsi:type="DataDocument"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fpml.org/2005/FpML-4-2 fpml-main-4-2.xsd"
xmlns="http://www.fpml.org/2005/FpML-4-2">

 

 

Since I had this problem then I created new functions, which I will
return the DataDocument instead Document based on FpML functions. These
functions work well. But in the header would have to be "xsi: type =
DataDocument", but not shown this, it is because I am showing the Object
DataDocument, so my question is whether it is possible to put this
attribute in the header.

 

Code:

 

    auto_ptr<DataDocument> dDocument(FpML_DD("xml_swap.xml"));

 

    xml_schema::namespace_infomap map;

    map[""].name   = "http://www.fpml.org/2005/FpML-4-2";

    map[""].schema = "fpml-main-4-2.xsd";

 

    std::ostringstream oss;

    ::FpML_4_2::FpML_DT(oss, *dDocument, map);

    std::string xml (oss.str ());

 

Show (Header):

 

<FpML xmlns="http://www.fpml.org/2005/FpML-4-2" actualBuild="3"
version="4-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://w

ww.fpml.org/2005/FpML-4-2 fpml-main-4-2.xsd">

 

 

For the attention to this mail a thousand thanks

 

Note: I attached the project that I have been using and xml file and xsd
files. And xml file that I'm using is an example of the scheme FpML so
it cannot be wrong file.  Ahhh sorry for my English.

 

The project is in VisuaStudio 2005

The XSD is  xsd-3.3.0 with xerces-c.3.1.1

 

 

 

 

Saludos Cordiales

 

Roberto Escobar

 

 



More information about the xsd-users mailing list