Groups | Blog | Home
all groups > dotnet xml > june 2007 >

dotnet xml : Which is the root element


David Thielen
6/30/2007 3:56:02 PM
Hi;

I have an xsd that has:
<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
<xsd:element name="comment" type="xsd:string"/>

I get this as an XmlSchema using:
XmlSchema schema = XmlSchema.Read(new FileStream(datasource.SchemaUrl,
FileMode.Open, FileAccess.Read, FileShare.Read), null);
schema.Compile(null);

Two questions:

1) Is this the best way to get the schema? I am getting a warning that I
should put it in an XmlSchemaSet and compile the set although this is my only
schema.

2) The <purchaseOrder> element is the root node. But how do I know that from
the xsd file? Is the root node always the first one and the rest are for
references?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

John Saunders [MVP]
6/30/2007 7:54:27 PM
[quoted text, click to view]

I suggest you follow what the warning is telling you. XmlSchemaSet will
allow for the possibility in the future that the first schema might refer to
a second, or that your instance document will some day require more than one
schema to describe it.

[quoted text, click to view]

The schema fragment you've supplied permits either <purchaseOrder> or
<comment> to be the root node in an instance document that validates against
this schema (assuming it's the only schema being used).

What are you trying to accomplish? What is it about the "root node" that you
want to find out?
--
John Saunders [MVP]
David Thielen
7/1/2007 7:04:00 AM
We want to have a wizard that helps the user create valid XPath statements
for the xml. So we put the schema in a TreeView that they can click on to
select elements.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
John Saunders [MVP]
7/2/2007 11:26:23 AM
[quoted text, click to view]

Ok, then I think you may need to change your schema to have only one global
element, hence only one possible root node.
--
John Saunders [MVP]
druqlqrvsd
8/25/2007 7:26:46 PM
AddThis Social Bookmark Button