[xsd-users] Cxx-Tree binding the LandXML schema - Help accessint
the elements data
Boris Kolpackov
boris at codesynthesis.com
Fri Feb 27 09:40:03 EST 2009
Hi Constantin,
You sent your email to the wrong mailing list. xsde-users is for XSD/e
while your question is for XSD and should be sent instead to xsd-user.
In the future, please make sure you use the correct mailing list.
Constantin Iacobescu <sir.costy at gmail.com> writes:
> Hello,
>
> I'm a bit beginner with XML parsing and less with XSD, so some help would be
> appreciated.
>
> I'm using Windows version of XSD Cxx-Tree for binding the LandXML schema and
> so on the binding was without errors. This is the command line used:
> xsd cxx-tree --generate-serialization --generate-polymorphic
> --generate-doxygen --generate-wildcard --generate-ostream --type-naming java
> --function-naming java --file-per-type --namespace-map
> http://www.landxml.org/schema/LandXML-1.0=LandXML_10 LandXML-1.0.xsd
>
> Then I'm parsing some xml file and display the content on the screen.
> Striped code should be some like this:
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> using namespace xercesc;
>
> XMLPlatformUtils::Initialize ();
>
> try
> {
> namespace xml = xsd::cxx::xml;
>
> std::auto_ptr<LandXML_10::LandXML> objLandXML (
> LandXML_10::parseLandXML(argv[1], xml_schema::Flags::dont_initialize));
>
> LandXML_10::LandXML::CgPointsSequence&
> cgPoints(objLandXML->getCgPoints());
>
> for (LandXML_10::LandXML::CgPointsIterator ptsIter(cgPoints.begin());
> ptsIter != cgPoints.end ();
> ++ptsIter)
> {
> LandXML_10::CgPoints::NameOptional& optName(ptsIter->getName());
> if (optName.present())
> cerr <<"name:"<< optName.get() << endl;
>
> LandXML_10::CgPoints::CgPointSequence
> cgPoint(ptsIter->getCgPoint());
>
> for (LandXML_10::CgPoints::CgPointIterator ptIter(cgPoint.begin());
> ptIter != cgPoint.end ();
> ++ptIter)
> {
> LandXML_10::CgPoint::NameOptional& optCode(ptIter->getCode());
> if (optCode.present())
> cerr <<"code:" << optCode.get() << endl;
>
> cerr << *ptIter <<endl ;
> ???????????? How to get the data stored here ?????
The CgPoint type has mixed content. There are two ways to handle
this. You can use the DOM association feature and retrieve the
text from the corresponding DOM node. The 'mixed' example in the
examples/cxx/tree/ directory shows how to do this. This method
will only work for parsing.
Alternatively, you can customize the generated CgPoint class and
add a string member to it that will store the element value. You
will also need to override the parsing constructor to extract the
element value from DOMElement and store it in the member as well
as the serialization operator to serialize the element value to
DOMElement. The 'wildcard' example in the examples/cxx/tree/custom/
directory shows how to do something like this. For more information
on type customization refer to the C++/Tree Mapping Customization
Guide:
http://wiki.codesynthesis.com/Tree/Customization_guide
[The rest of the original email follows for context.]
>
> }
> }
> catch (const xml_schema::Exception& e)
> {
> cerr << e << endl;
> }
>
> XMLPlatformUtils::Terminate ();
> }
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> As can be seen I can access the elements and display the attributes of them.
> Even more, using the --generate-ostream option I can display all the content
> of an element attributes + data.
>
> My question is how I can get the data stored by a element in a std::string
> for process it further more.
>
> I've tried to made something like this (like I seen in some example):
>
> DOMElement& e (*ptIter);
>
> But got a compiler error: >>> error C2440: 'initializing' : cannot convert
> from 'LandXML_10::CgPoint' to 'xercesc_3_0::DOMElement &'
>
> Please if someone can give me some advices. Thanks
>
> Best Regards,
> Constantin Iacobescu
Boris
More information about the xsd-users
mailing list