Page 1 of 1

Element basics

Posted: Tue Jul 12, 2011 5:43 pm
by senseiwa
Hi! I am trying to figure out if an element can have both a type and attributes. So that something like this can be validated via a schema:

Code: Select all


<element name="Hello">World</element>
<element name="This">Text</element>

Thanks!

Re: Element basics

Posted: Wed Jul 13, 2011 5:10 pm
by adrian
Hello,

Of course it can have both. The following schema snippet covers this:

Code: Select all

  <xs:element name="element">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Obviously you can use a different type than xs:string.

You can easily generate a schema for content like this in Oxygen:
- Make the XML snippet well-formed(put it inside an XML root) and open it in Oxygen:

Code: Select all

<root>
<element name="Hello">World</element>
<element name="This">Text</element>
</root>
- Use the schema generator/converter(Document -> Schema -> Generate/Convert Schema), select W3C XML Schema check the output filename of the generated schema and press Convert.

You will obtain a simple XML Schema that contains an element declaration similar to the one mentioned above.

Regards,
Adrian