Element basics

Questions about XML that are not covered by the other forums should go here.
senseiwa
Posts: 5
Joined: Wed May 04, 2011 4:03 pm

Element basics

Post 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!
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Element basics

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply