XSD to create an element with Namespace as prefix
I want to create an XSD which can gene开发者_StackOverflow社区rate the following XML.
<note>
<email:to>abc@def.com</email:to>
<from>xyz@def.com</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.
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="abc@def.com"/>
<email><to>abc@def.com</to></email>
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.
精彩评论