[xsd-users] Reading from istream
Boris Kolpackov
boris at codesynthesis.com
Fri May 12 07:47:55 EDT 2006
Hi David,
I am still replying to your previous email. ;-)
Moss, David R (SELEX Comms) (UK Christchurch) <david.r.moss at selex-comm.com> writes:
> string str ("<mn:mainCfg
> xmlns:mn=\"http://www.d_moss.com/dm_schema/main\"
> xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xsi:schemaLocation=\"http://www.d_moss.com/dm_schema/main
> main.xsd\"><main><item>88</item></main></mn:mainCfg>");
>
> istringstream iss( str );
> auto_ptr<mainCfg_t> r( mainCfg(iss) );
> cout << *r << endl;
>
> outputs
>
> main:
> item: 88
>
> Is it possible to read a fragment of xml (e.g. "<item>88</item>")
> without having to include all the namespace information? I've had a play
> around with the properties:: schema_location() into the mainCfg
> constructor without any success!
Generated constructors that are used to create the tree from XML expect
pre-parsed DOM elements, not a text representation of XML. The easiest
way to achieve what you want (especially if you want the fragment to
be validated) is to add a global element for the fragment into your
schema:
<xsd:element name="item" type="mn:item_t"/>
This achieves two things: (1) it makes the fragment's root element
a valid document root (needed for validation) and (2) XSD will
generate parsing functions for it which we can use.
While you can specify the schema to be used for validation outside
your fragment (see FAQ 2.4[1]), you will still need to add namespace-
to-prefix mapping to your fragment since it's the only place this can
be done, for example
string str (
"<item xmlns=\"http://www.d_moss.com/dm_schema/main\">88</item>");
istringstream iss (str);
auto_ptr<item_t> r (
item (iss, /* use property for external schema, FAQ 2.4*/));
cout << *r << endl;
Should print:
88
[1] http://codesynthesis.com/projects/xsd/documentation/cxx/tree/faq/#2.4
hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060512/7ffc283e/attachment.pgp
More information about the xsd-users
mailing list