C# xsd xmlreader, how to count attribute names -
this simple guys, need able count attribute names within xml document when validating xml against schema using c#. duplicate attribute names (not valid).
if xsd has these in it:
<xsd:schema> <xsd:complextype name="scheduleevent"> <xsd:all> <xsd:element name="basic" type="mybasic"/> </xsd:all> </xsd:complextype> <xsd:complextype name="mybasic"> <xsd:choice minoccurs="0" maxoccurs="unbounded"> <xsd:element name="descriptor" type="descriptor" maxoccurs="1"/> <xsd:element name="descriptor1" type="descriptor1" maxoccurs="1"/> </xsd:choice> </xsd:complextype> <xsd:complextype name="descriptor"> <xsd:attribute name="test" type="typ:test"/> </xsd:complextype> <xsd:complextype name="descriptor1"> <xsd:attribute name="test1" type="typ:test1"/> </xsd:complextype>
and xml validate against looks (not valid, know quick mock example reference:
declarations etc...
<scheduleevent> <mybasic> <descriptor test="02"/> <descriptor1 test1="02" test1="02"/> </mybasic> </scheduleevent>
how can count number of "test1" attributes? c# xmlreader (without using exceptions, long story).
first of all, isn't valid xml. attribute unique per element.
if ment can have multiple "test1" attributes throughout different elements, can following using linq xml:
var xml = xdocument.load(@"pathtoxml"); var testcount = xml.descendants().attributes("test1").count();
Comments
Post a Comment