Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Example of Schema for XML Newbie...

Status
Not open for further replies.

johnny76

Programmer
Feb 14, 2006
24
CA
Hi,
I have been progomming for a number years now and I need to look into XML. Can I get a couple of pointers to get me started in XML. I currently understand the XML doc format and schema format.

What I am looking for is a basic how to example of on validating using schema. Just simple sample code to get me going in the right direction. Say one XML file with two fields and simple fields validation using a schema. How do the fields get validated.

Craig
 
Thanks for the reply. I have actually already been through their tutorials. I understand how to create the xml and the schema but it doesn't really explain how you use them together.

Any tips?

Craig
 
Is there anyone that can help me out at all in this situation?

I have a test xml document:
Code:
<?xml version="1.0"?>
<note xmlns="[URL unfurl="true"]http://www.w3schools.com"[/URL]
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="Note - Schema.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Here is my schema:

Code:
<?xml version="1.0"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]
targetNamespace="[URL unfurl="true"]http://www.w3schools.com"[/URL]
xmlns="[URL unfurl="true"]http://www.w3schools.com"[/URL]
elementFormDefault="qualified"><xs:element name="note">
    <xs:complexType>
      <xs:sequence>
	<xs:element name="to" type="xs:int"/>
	<xs:element name="from" type="xs:string"/>
	<xs:element name="heading" type="xs:string"/>
	<xs:element name="body" type="xs:int"/>
      </xs:sequence>
    </xs:complexType>
</xs:element></xs:schema>

Very simple validation...my question is how do I actually validate with this schema?

I am a programmer so I am looking for some function calls or something...but I am a little confused....any suggestions would be great...

CES
 
Thanks again for the reply.

I guess what I am really not seeing is how I can create an xml document and then validate it programatically useing php for instance.

All I really need to get me going is a very basic xml doc and a very basic schema. Then maybe directed how I go about validating using the schema and say php...

What I am confused about is where the validation takes place I guess.

Does what I am saying make sense to you?

If not feel free to ask more questions...could really use the help. Thanks again.

CES
 
To:Op

One thing that I'm curious is : are the xml and xsd got directly from w3schools? It looks incorrect. Not only it won't validate (may be that's a point too for validation to fail), it's schemaLocation construction is wrong?

As to the step-by-step walk through the validation process, if you use windows platform, you can use msxsl to parse the the xml file with a dummy/simple stylesheet using the switch option -v. If the validation process fails, the error will be displayed in the console.

If you do xml in php environment, there is bound to have some .validateOnParse=true for the parser just like msxml core service. You just need to locate an example in the net. But a commandline validation like using msxsl.exe or alike (saxon .. ) or the simple and one of the earliest validators like xsv of Thompson and Tobin would be the most illustrative and you will learn more from it. The more "sophisticate" environment like using PHP, the more ritual the thing becomes, hence it is simpler rather than more difficult.

Why not try msxsl or xsv to start with?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top