i am using an XMLValidatingReader in a manner similar to the following
code example:
string sReturn = "";
XmlValidatingReader oXML = new XmlValidatingReader(sXMLString,
XmlNodeType.Document, null);
oXML.Schemas.Add("", sSchemaURL);
oXML.ValidationType = ValidationType.Schema;
oXML.ValidationEventHandler += new
ValidationEventHandler(ValidationHandler);
while(oXML.Read())
{
if (oXML.NodeType == XmlNodeType.Element)
{
sReturn = sReturn + "Name: " + oXML.LocalName + "<br>";
sReturn = sReturn + "Value: " + oXML.Value + "<br><br>";
}
}
using the following sample schema:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myobject">
<xs:complexType>
<xs:sequence>
<xs:element name="objectid" type="xs:integer" />
<xs:element name="objectdescription" type="xs:string" />
</xs:sequence>
</xs:complextType>
</xs:element>
and the following sample instance document:
<?xml version="1.0" encoding="utf-8" ?>
<myobject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="Schema.xsd">
<objectid>1</objectid>
<objectdescription>Red</objectdescription>
</myobject>
i am getting the following results as output:
Name: myobject
Value:
Name: objectid
Value:
Name:
Value: 1
Name: objectid
Value:
Name: objectdescription
Value:
Name:
Value: Red
Name: objectdescription
Value:
Name: myobject
Value:
my question is: is there a way to write the xml elements such that the
names of elements are matched up with their values? as it is, i can fix
this with an extra Read statement like so:
while(oXML.Read())
{
if (oXML.NodeType == XmlNodeType.Element)
{
sReturn = sReturn + "Name: " + oXML.LocalName + "<br>";
oXML.Read();
sReturn = sReturn + "Value: " + oXML.Value + "<br><br>";
}
}
but that seems like it should be unnecessary. it seems like the element
name should already be matched with the element value?
thanks for any help / guidance,
jason