tags:

views:

25

answers:

2

I want to create an XSD which can generate the following XML.

<note>
<email:to>[email protected]</email:to>
<from>[email protected]</from>
</note>

How to write XSD element definition for the element.

<xsd:element name="note">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="email:to" type="xsd:string"/>
<xsd:element name="from" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

Here the element name "email:to" fails validation.

How can I represent this in XSD?

Thank you.

A: 

The : symbol in XML represents XML namespace syntax, which isn't appropriate to what you're trying to do. You can't use that symbol in XML without the processors interpreting it as a namespace.

You might want to consider using one of the two alternatives:

<email to="[email protected]"/>
<email><to>[email protected]</to></email>
skaffman
A: 

Would like to add some more points, Naming XML elements follow the same rule as applied for declaring variables in any programming langs,

  • The characters appearing in element name can be any alpha-numeric character or underscore
  • Name can start with a alpha character [numbers or _ not allowed as first char]
  • IMPORTANT : names can't be of pattern [or cannot start with the letters) xml or XML or Xml
  • Also spaces are not allowed

So abiding which certainly leads to validation error.

infant programmer