Jump to content

need help with writing schema


crr
 Share

Recommended Posts

I am new to writing schemas and I am trying to write a schema for the following xml file:

 

<?xml version="1.0"?><resumexmlns="http://w3schools.com/res" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://w3schools.com/res rcopy.xsd" ><name> Jane </name><address><street> This is the street </street><city>xyz</city><state>CA</state><zipcode>11111</zipcode></address><phone area="650">000-2000</phone><comment>Thank you for reading </comment></resume>

 

 

The xsd code I wrote is (rcopy.xsd) :

------------------------------------------

 

<?xml version="1.0" ?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"targetNamespace="http://w3schools.com/res"xmlns="http://w3schools.com/res" elementFormDefault="qualified"><xsd:element name="resume" /><xsd:element name="name" type="xsd:string"/><xsd:element name="address"><xsd:complexType><xsd:sequence><xsd:element name="street" type="xsd:string"/><xsd:element name="city" type="xsd:string"/><xsd:element name="state" type="xsd:string"/><xsd:element name="zip" type="xsd:string"/></xsd:sequence></xsd:complexType></xsd:element><xsd:element name="phone"> <xsd:complexType> <xsd:sequence> <xsd:element name="phone" type="xsd:string" /> </xsd:sequence> <xsd:attribute name="area" type="xsd:string" /></xsd:complexType></xsd:element><xsd:element name="comment" type="xsd:string"/></xsd:schema>

 

When trying to validate it with xmllint I am getting the following error:

 

xmllint --noout --schema rcopy.xsd rcopy.xml

 

rcopy.xml:16: element phone: Schemas validity error : Element '{http://w3schools.com/res}phone': Character content other than whitespace is not allowed because the content type is 'element-only'.rcopy.xml:16: element phone: Schemas validity error : Element '{http://w3schools.com/res}phone': Missing child element(s). Expected is ( {http://w3schools.com/res}phone ).rcopy.xml fails to validate

 

 

Any help in correcting my problem will be helpful..

 

Thanks

Edited by crr
Link to comment
Share on other sites

I was able to do it this way...which i hope is right.

 

<xsd:element name="phone"> <xsd:complexType> <xsd:simpleContent> <xsd:extension base="xsd:string" > <xsd:attribute name="area" type="xsd:string" /> </xsd:extension> </xsd:simpleContent></xsd:complexType></xsd:element>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...