With the following XSD:
<!---------------------------Start of Form.xsd--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="FormDefin ition">
<xs:complexType >
<xs:sequence>
<xs:element name="FormName" minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
</xs:element>
<xs:element name="FormTitle " minOccurs="0">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="xs:string ">
<xs:attribute name="ReadFromD B" type="xs:boolea n" use="required"/>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
</xs:element>
</xs:schema>
<!---------------------------End of Form.xsd--------------------------->
And the following XML Document
<!---------------------------Start of Test.xml--------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Form.xsd">
<FormName id="a1">test form </FormName>
<FormTitle ReadFromDB="tru e" id="a2">Island </FormTitle>
</FormDefinition>
<!---------------------------End of Test.xml--------------------------->
xmlDoc1.GetElem entById("a1") is returning null. How can i fix this? Can I
have an xs:ID that contains numbers only? Is there a method to search for a
node given an id attribute instead?
"Patrick" wrote:
Is it actually valid to have an XML document with 2 XML Elements having the
same ID attribute? XML Spy seems to allow something like the following
<?xml version="1.0" encoding="UTF-8"?>
<FormDefiniti on xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Forms.xsd" >
<list id="1">
<status>partial ly completed</status>
</list>
<list id="1">
<status>complet ed</status>
</list>
</FormDefinition>
If it is valid, how can I utilise System.Xml.XmlD ocument.GetElem entById
method() (which returns 1 XmlNode)?