• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Schemas

 
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am learning xml schemas.

I have created a schema as follows pen.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="abcd"
targetNamespace="efgh"
xmlns="hello"
elementFormDefault="qualified">

<xs:element name="pen">
<xs:complexType>
<xs:sequence>
<xs:element name="color" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>


The xml document pen.xml is as follows:

<?xml version="1.0"?>

<note xmlns="hello"
xmlns:xsi="good"
xsi:schemaLocation="yes pen.xsd">

<dear>Tove</dear>
</note>

Now if I open this xml in Internet Explorer is should is throw an error since it expects an element called color in the xml.

But that does not happen.
How do I apply the xml schema to the xml and get it tested if its is working.
Is there anything wrong with my xml or my xsd.

Priety.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's your schema. A complex type definition should look like this:


I noticed you used xs: but it should have been xsd: and you got an extra later of element, which is redudant to define complex types.

Hope this helps.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There might indeed be problems with the schema -- but I'm not a schema expert. I do know that browsers won't validate XML when they display it, though.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Now I have changed things in my xml and my schema:

This is the new ranch.xml
It has a single element called dear
It mentions ranch.xsd as the schema for its validation:

<?xml version="1.0"?>

<note xmlns="hello"
xmlns:xsi="good"
xsi:schemaLocation="yes ranch.xsd">

<dear>Tove</dear>
</note>


This is the schema ranch.xsd

<?xml version="1.0"?>
<xsd:schema xmlns:xs="abcd"
targetNamespace="efgh"
xmlns="hello"
elementFormDefault="qualified">

<xsd:complexType name="pen">
<xsd:sequence>
<xsd:element name="color" type="colorType" />
</xsd:sequence>
</xsd:complexType>


</xsd:schema>

Now when I open the ranch.xml in Internet Explore I expect it to be validated agains the ranch.xsd schema and the browser should show an error, but it does not happen.
Then what is the use of mentioning the schema in the xml if the browser is not validation against it.

Priety.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a few xml files and they don't get validated when it is loaded. However, there is a validator online I just found http://tools.decisionsoft.com/schemaValidate/ that will validate your file against your schema. I ran my files through it and guess what... my schemas were invalid. Then I "make" them valid.

I'm sure if you use DTD then when the xml file is loaded in the browser, it will prompt error if your DTD doesn't match.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot K. Tsang for the online validator link.

Yes as you said it does work.

Priety.
reply
    Bookmark Topic Watch Topic
  • New Topic