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.SelectS ingleNode("desc endant::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"
elementFormDefa ult="qualified"
attributeFormDe fault="qualifie d" xmlns="http://tempuri.org/ClusterDS.xsd"
xmlns:mstns="ht tp://tempuri.org/ClusterDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="ClusterDS " msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="Cluster">
<xs:complexType >
<xs:sequence>
<xs:element name="ClusterID " msdata:ReadOnly ="true"
msdata:AutoIncr ement="true" type="xs:long" />
<xs:element name="FrameID" msdata:ReadOnly ="true"
msdata:AutoIncr ement="true" type="xs:long" />
<xs:element name="Type" type="xs:string " minOccurs="0" />
<xs:element name="XCoordina te" type="xs:long" minOccurs="0" />
<xs:element name="YCoordina te" type="xs:long" minOccurs="0" />
<xs:element name="RedColor" type="xs:unsign edByte" minOccurs="0" />
<xs:element name="GreenColo r" type="xs:unsign edByte" minOccurs="0" />
<xs:element name="BlueColor " type="xs:unsign edByte" 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>20 0</XCoordinate>
<YCoordinate>10 0</YCoordinate>
<RedColor>0</RedColor>
<GreenColor>0 </GreenColor>
<BlueColor>25 5</BlueColor>
</Cluster>
<Cluster>
<ClusterID>1</ClusterID>
<FrameID>0</FrameID>
<Type>0</Type>
<XCoordinate>25 0</XCoordinate>
<YCoordinate>30 0</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
made using an XML schema (XSD),
When I;m using the following code:
XmlDocument cluster = new XmlDocument();
cluster.LoadXml (xmlCluster);
XmlNode node = cluster.SelectS ingleNode("desc endant::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"
elementFormDefa ult="qualified"
attributeFormDe fault="qualifie d" xmlns="http://tempuri.org/ClusterDS.xsd"
xmlns:mstns="ht tp://tempuri.org/ClusterDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="ClusterDS " msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="Cluster">
<xs:complexType >
<xs:sequence>
<xs:element name="ClusterID " msdata:ReadOnly ="true"
msdata:AutoIncr ement="true" type="xs:long" />
<xs:element name="FrameID" msdata:ReadOnly ="true"
msdata:AutoIncr ement="true" type="xs:long" />
<xs:element name="Type" type="xs:string " minOccurs="0" />
<xs:element name="XCoordina te" type="xs:long" minOccurs="0" />
<xs:element name="YCoordina te" type="xs:long" minOccurs="0" />
<xs:element name="RedColor" type="xs:unsign edByte" minOccurs="0" />
<xs:element name="GreenColo r" type="xs:unsign edByte" minOccurs="0" />
<xs:element name="BlueColor " type="xs:unsign edByte" 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>20 0</XCoordinate>
<YCoordinate>10 0</YCoordinate>
<RedColor>0</RedColor>
<GreenColor>0 </GreenColor>
<BlueColor>25 5</BlueColor>
</Cluster>
<Cluster>
<ClusterID>1</ClusterID>
<FrameID>0</FrameID>
<Type>0</Type>
<XCoordinate>25 0</XCoordinate>
<YCoordinate>30 0</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
Comment