asp.net - Parsing xml dynamic tag using c# -
i'm c# learner , i've been facing situation:
here sample of xml i'm working on
<user_security> <bob> <group>s1, a2, b3</group> </bob> <alice> <group>y3, c2</group> </alice> </user_security>
as can see uses people tag name not tag data, cannot use getelementbytagname() xmldocument
how can parse both name , groups belong?
edit: know doesn't answer exact question of how solve problem current xml; many people have commented, xml subject malformation , cause lot of problems. i've worked xml far more sane person should coerced doing , advice offer save lot of heartache.
good luck!
what use attributes , maybe xsd schema.
make this
<user_security> <user name="bob"> <group>c1</group> <group>c2</group> <group>c3</group> </user> <user name="alice"> <group>c1</group> <group>c2</group> </user> </user_security>
you can use xsd file allowed multiple groups in user; i'll find example , post in edit.
edit: xsd fragment this, you'll have learn whole concept:
<xs:element name="user"> <xs:attributename="name" type="xs:string" /> <xs:complextype> <xs:choice> <xs:element name="group" type="xs:string" minoccurs="1" maxoccurs="unbounded"/> </xs:choice> </xs:complextype> </xs:element>
an alternate way block be:
<xs:element name="user"> <xs:attributename="name" type="xs:string" /> <xs:simpletype name="sku"> <xs:restriction base="xs:string" /> </xs:simpletype> </xs:element>
this lets validate xml input , ensure user node must use name attribute , can have 1..many groups must strings.
Comments
Post a Comment