Jump to content

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..



Edited by crr
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>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...