[xsd-users] Reading from istream

Moss, David R (SELEX Comms) (UK Christchurch) david.r.moss at selex-comm.com
Fri May 12 09:32:50 EDT 2006


Boris,

> From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> Sent: 12 May 2006 12:48
> I am still replying to your previous email. ;-)

Just keeping you busy! :-)

> 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:

Although this works, would you not end up in a situation where all types
are made valid document roots just because fragment validation is
required...? 


> 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

Thanks for that - forgot to look at the FAQ!


Cheers,
Dave.

Dave Moss
SELEX Communications
Grange Road
Christchurch 
Dorset  BH23 4JE
United Kingdom
Tel: + 44 (0) 1202 404841
Email: david.r.moss at selex-comm.com


> -----Original Message-----
> From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> Sent: 12 May 2006 12:48
> To: Moss, David R (SELEX Comms) (UK Christchurch)
> Cc: xsd-users at codesynthesis.com
> Subject: Re: [xsd-users] Reading from istream
> 
> 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




More information about the xsd-users mailing list