Jump to content
Sign in to follow this  
crr

need help with writing schema

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

Share this post


Link to post
Share on other sites

It sounds like it is expecting the phone element to have another phone element as the child. e.g.:

 

<phone><phone>...

 

It looks like the schema says to have a phone element inside the other phone element.

Share this post


Link to post
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>

Share this post


Link to post
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
Sign in to follow this  

×