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

Validating XML file with local XSD file 1

Status
Not open for further replies.

DougieDa59

Programmer
Mar 10, 2010
3
GB
Hey folks,
I'm pretty new to XML so bare with me..

I'm trying to validate an XML file using a XSD file in the same directory. The reference I have in the xml file is:
Code:
<?xml version="1.0" encoding="utf-8"?>
<newsandscores xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
         xsi:noNamespaceSchemaLocation="C:\news.xsd">

And at the top of the XSD file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
    elementFormDefault="qualified"
    xmlns="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
    xmlns:mstns="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
    xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]

In the XML file, I have purposely entered a string into an attribute which is defined as an integer in the XSD in the hopes that either Visual Studio or Firefox would show it up as an error but neither do.

Any ideas?
Thanks in advance...
 
The vocab, such as newsandscores, is in the (target) namespace. I deduce there should be a default namespace declared. Further, the schema doc and the xml doc are in the same directory.
[tt]
<newsandscores
[red]xmlns="[ignore][/ignore]"[/red]
xmlns:xsi="[ignore][/ignore]"
xsi:[red]schemaLocation="[ignore] news.xsd[/ignore]"[/red]
>[/tt]
 
That often just means the schema is not properly constructed to reflect the existing xml doc or the inverse, the xml doc is constructed violating the schema definition. That cannot be resolved without detail study of the schema and the xml doc. When doing validating, that is a normal course of business, and that is the purpose of validation.
 
Ah, thank you very much Tsjui.. had a quick look at my XSD and was able to spot the error.

VS is now throwing an error up where I have the string in an int field (which is what I wanted), so thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top