[xsd-users] XML Object to String/Text

Paddy Vishnubhatt Paddy.Vishnubhatt at 3leafnetworks.com
Wed Feb 21 11:45:46 EST 2007


w.r.t 2: 

There is some sample DOM manipulation code on the Wiki, see for example
3.1 and 3.2:

http://wiki.codesynthesis.com/Tree/FAQ <http://wiki.codesynthesis.com/Tree/FAQ> 

Q: Is there an API that I can generically use to create DOMDocument objects from any XSD-driven object?
--

________________________________

From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Wed 2/21/2007 7:10 AM
To: Paddy Vishnubhatt
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] XML Object to String/Text



Hi Paddy,

Paddy Vishnubhatt <Paddy.Vishnubhatt at 3leafnetworks.com> writes:

> 1. is there a simple way to get a stringified representation of the
>    object? Like in the Java API (xmlbeans), xmlText() or even toString()
>    which outputs a Sring representation of the given Xml Object?

You can use one of the serialization functions together with
std::ostringstream. For instance, in the library example there is
the this line:

// Write it out.
//
catalog_ (std::cout, *c, map);


You can replace it with something like this (also add #include <sstream>):


// Write it to string.
//
std::ostringstream ostr;

catalog_ (ostr, *c, map);

std::string str = ostr.str (); // XML is in str.





> 2. I see that there are documented ways to create DOMDocument from which
>    one can use DOMWriter to use writeString to get to ultimately get to
>    the string - is there an example/sample code that I can use for/as
>    reference.

There is some sample DOM manipulation code on the Wiki, see for example
3.1 and 3.2:

http://wiki.codesynthesis.com/Tree/FAQ

The ostringstream way is much easier though.


hth,
-boris





More information about the xsd-users mailing list