all groups > dotnet xml > june 2007 >
You're in the

dotnet xml

group:

How do I access a reference in XmlSchema?


How do I access a reference in XmlSchema? David Thielen
6/30/2007 3:58:00 PM
dotnet xml:
I have an xsd:
<xsd:element name="comment" type="xsd:string">
<xsd:annotation>
<xsd:documentation>hi there</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>

that I load into an XmlSchema object. One of the inner elements uses a
ref="comment" instead of a name=. Do I need to then walk the entire tree in
the XmlSchema to get the reference, or walk all the top level elements, or is
there a property I can use to access it directly?

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

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

Re: How do I access a reference in XmlSchema? John Saunders [MVP]
6/30/2007 9:15:23 PM
[quoted text, click to view]

ref can only refer to global elements. You only need to look at the
XmlSchemaSet.GlobalElements collection to see the possible root elements.
--
John Saunders [MVP]
Re: How do I access a reference in XmlSchema? David Thielen
7/1/2007 11:12:02 AM
Worked great - thanks.

I assume from the documentation when I see this that I ignore the properties
in the initial element (except for min/max/id if set) and instead the
reference is the element at this position and the reference then gives me any
attributes and child 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]
Re: How do I access a reference in XmlSchema? v-wywang NO[at]SPAM online.microsoft.com
7/3/2007 12:00:00 AM
Hello Dave
Thanks for John's idea.
XmlSchemaSet.GlobalElements is the best way to search the reference.

The schema you posted in newsgroup is equal to
<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>

<xsd:element name="comment" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>hi there</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>

If you get the reference, it will tell you all child element and
attributes. However, please don't forget the attribute in the initial
element. (such as the minOccurs="0" in the current case)

Hope this helps.
Sincerley,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: How do I access a reference in XmlSchema? hgbjxeiluw
8/25/2007 7:26:59 PM
AddThis Social Bookmark Button