In an XML Schema (XSD) I am writing, I need to define an attribute which can occur multiple times inside its parent element.
Just to clear it with an example : the parent element represent events, and it supports different attributes like a title and an occurrence date for instance. One of the attributes called department
is the organizing department. An event may be organized by one, or many departments.
I want to know if XSD can handle multiple instances of the same attribute in an element or if this is beyond the scope of XML Standard ?
attributes cannot contain multiple values (elements can) attributes cannot contain tree structures (elements can) attributes are not easily expandable (for future changes)
An element can have multiple unique attributes. Attribute gives more information about XML elements. To be more precise, they define properties of elements. An XML attribute is always a name-value pair.
Get the element node and use SetAttribute to add an attribute to the attribute collection of that element. Create an XmlAttribute node using the CreateAttribute method, get the element node, then use SetAttributeNode to add the node to the attribute collection of that element.
You can't. Attribute names are unique per element.
If you need to have multiple bits of data under the same name, then the usual solutions are either a space separated list or child elements.
<event department="foo bar baz" />
or
<event>
<department>foo</department>
<department>bar</department>
<department>baz</department>
</event>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With