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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in first steps in an example I created for xml schema 1

Status
Not open for further replies.

royboy75

Programmer
Feb 13, 2007
114
GB
Hello,

I am trying to create a simple XML which refers to an XML Schema file, but it looks like the XML doesn't care about the Schema it refers to (both files are sitting on the same directory).

Here is my test.xml file:
Code:
<?xml version="1.0"?>

<note
xmlns="[URL unfurl="true"]http://www.me.com"[/URL]
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.me.com[/URL] schema.xsd">

<to>Tove</to>
<from>Me</from>
<heading>Reminder</heading>
<body>Hello!</body>
</note>

Here is my schema.xsd:
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.me.com"[/URL]
xmlns="[URL unfurl="true"]http://www.me.com"[/URL]
elementFormDefault="qualified">

<xs:element name="note">
    <xs:complexType>
      <xs:sequence>
	<xs:element name="to" type="xs:string"/>
	<xs:element name="from" type="xs:decimal"/>
	<xs:element name="heading" type="xs:string"/>
	<xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

Now, if I change for example:
<xs:element name="to" type="xs:string"/>
to:
<xs:element name="to" type="xs:decimal"/>

The test.xml is still working and doesn't throw an error that to should be decimal.
What I am doing wrong here?
 
As of what shown, nothing wrong. Nevertheless, the schemaLocation can be overriden and by itself is not 100% assuring factor. The problem is in your calling of the validating utility and/or the setting of validating process of the utility.
 
I am opening the XML in standard internet explorer.
Can you please elaborate this?
 
>I am opening the XML in standard internet explorer.
Then you are relying on the default stylesheet and setting of the ie and it is not validating the document by default.
 
So what do I need to do in order for it to be validated?
 
So if I understand correctly without this tool no validation will be made.
Now, I intend to expose this xml in the future to our users through the internal Web. Do you say that unless each user has this tool the xml could not be validated against this schema? Now, of course that the validation needs to be validated only once by the developer but what if this schema contains designing properties as well? The users won't notice them without this tool?
I might be confusing here so I will be happy to get some more elaborated explanation.

Roy
 
Every major xml-aware technology has its own validating utility usually going with its parser(s). You have to do simple goolge on xml validation referring the technology you're using.

For ms, it is natural you have to use msxml2 core service. For simple gui loading into ie, I suppose the mentioned add-on would do the thing. For other applications which are using or not using ie browser, at the end, it is still the msxml2 core service in the working. It depends then therefrom how the document is being served,...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top