I'm using an XML document that has a list of 'Clusters', this XML file is
made using an XML schema (XSD),
When I;m using the following code:
XmlDocument cluster = new XmlDocument();
cluster.LoadXml(xmlCluster);
XmlNode node = cluster.SelectSingleNode("descendant::FrameID"); // Errror:
Return null;
The node is null.
But when I remove the schema from the XML file is works fine.
Can anybody explain why it does not work when the schema is attached to the
XML file?
What code will work in both cases?
The XSD file:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="ClusterDS" targetNamespace="http://tempuri.org/ClusterDS.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/ClusterDS.xsd"
xmlns:mstns="http://tempuri.org/ClusterDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ClusterDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Cluster">
<xs:complexType>
<xs:sequence>
<xs:element name="ClusterID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:long" />
<xs:element name="FrameID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:long" />
<xs:element name="Type" type="xs:string" minOccurs="0" />
<xs:element name="XCoordinate" type="xs:long" minOccurs="0" />
<xs:element name="YCoordinate" type="xs:long" minOccurs="0" />
<xs:element name="RedColor" type="xs:unsignedByte" minOccurs="0" />
<xs:element name="GreenColor" type="xs:unsignedByte" minOccurs="0" />
<xs:element name="BlueColor" type="xs:unsignedByte" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
The XML file:
<?xml version="1.0" encoding="utf-8"?>
<ClusterDS xmlns="http://tempuri.org/ClusterDS.xsd">
<Cluster>
<ClusterID>0</ClusterID>
<FrameID>0</FrameID>
<Type>0</Type>
<XCoordinate>200</XCoordinate>
<YCoordinate>100</YCoordinate>
<RedColor>0</RedColor>
<GreenColor>0</GreenColor>
<BlueColor>255</BlueColor>
</Cluster>
<Cluster>
<ClusterID>1</ClusterID>
<FrameID>0</FrameID>
<Type>0</Type>
<XCoordinate>250</XCoordinate>
<YCoordinate>300</YCoordinate>
<RedColor>0</RedColor>
<GreenColor>255</GreenColor>
<BlueColor>0</BlueColor>
</Cluster>
<Cluster>
<ClusterID>2</ClusterID>
<FrameID>0</FrameID>
<Type>0</Type>
<XCoordinate>10</XCoordinate>
<YCoordinate>50</YCoordinate>
<RedColor>255</RedColor>
<GreenColor>0</GreenColor>
<BlueColor>0</BlueColor>
</Cluster>
</ClusterDS>
------------
Thanks
Sharon