[xsd-users] reading and writing non root elements

Greg Carter greg at permedia.ca
Mon Nov 27 18:31:24 EST 2006


Hi Boris,

Thanks for the reply.  I am trying to use the code given to read in an 
XML doc but I am getting errors at the point where the string is read 
into a DOMDocument object ( the parser->parse(wrap) line in the parse 
function).   I get a bunch of "error: Unknown Element 'MyEleType" and 
"error: Attribute 'someAtt' is not declared for element 'MyEleType'"

Do I need to tell Xerces about the schema that defines MyEleType?

Thanks
Greg.

Boris Kolpackov wrote:
> Hi Greg,
>
> Greg Carter <greg at permedia.ca> writes:
>   
> The other approach uses generated type's constructors and serialization
> operators to parse/serialize the type instance into XML. It also requires
> some dealing with Xerces-C++.
>
> First, let's consider the parsing case. We are going to use the helper
> function that is shown in the Q 2.1 of the Wiki FAQ[1]. The first
> step is to parse your XML string to DOM:
>
> #include <sstream>
>
> using namespace xercesc;
> namespace xml = xsd::cxx::xml;
>
> XMLPlatformUtils::Initialize ();
>
> {
>   std::istringstream is ("<your XML goes here>");
>   xml::dom::auto_ptr<DOMDocument> doc (parse (is));
>
> Then we need to get to the root DOMElement which we can pass to the
> ElOneType's constructor:
>
>   DOMElement& e (*doc->getDocumentElement ());
>
>   ElOneType el_one (e);
>
> }
>
> XMLPlatformUtils::Terminate ();
>   




More information about the xsd-users mailing list