Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Validating XML against Schema Validating XML against SchemaTo: NULL Date: 7/2/2004 6:56:00 AM Hello All,
I am having trouble validating an XML files against its Schema file
using .net System.XML class library and MSXML4, MSXML3 as well. Here
is the sample how my xml file and schema file looks like.
Schema file 1 : tmpGlobals.xsd.
-----------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.temp.com/tmpGlobals"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tmpGlobals="http://www.temp.com/tmpGlobals"
elementFormDefault="unqualified">
<xsd:simpleType name="phoneType">
<xsd:restriction base="xsd:normalizedString">
<xsd:pattern value="
BUSN|CAMP|CELL|DORM|FAX|HOME|OPH1|OPH2|PGR1|PGR2|T
ELX"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="servicePointId">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{10}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="serviceAddress">
<xsd:sequence>
<xsd:element name="servicePoint" type="tmpGlobals:servicePointId"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
-----------------------------------------------------------------------------
Schema file 2 : account.xsd
-----------------------------------------------------------------------------
<xs:schema elementFormDefault="unqualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tmpGlobals="http://www.talgov.com/tmpGlobals">
<xs:import namespace="http://www.talgov.com/tmpGlobals"
schemaLocation="tmpGlobals.xsd"/>
<xs:element name="AccountUpdate">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountInformation" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="phone" type="tmpGlobals:phoneType" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="serviceAddress" type="tmpGlobals:serviceAddress"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lifeSupportServicePoint"
type="tmpGlobals:servicePointId" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
-----------------------------------------------------------------------------
And my XML file looks like. test01.xml
-----------------------------------------------------------------------------
<AccountUpdate xmlns:tmpGlobals="http://www.talgov.com/tmpGlobals"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.talgov.com/globals account.xsd">
<AccountInformation>
<accountId>1234567890</accountId>
<phone>
<phoneType>HOME</phoneType>
</phone>
<entityName>Scott, Brian</entityName>
<serviceAddress>
<servicePoint>1234567890</servicePoint>
</serviceAddress>
</AccountInformation>
<lifeSupportServicePoint>2395932592</lifeSupportServicePoint>
</AccountUpdate>
-----------------------------------------------------------------------------
Whenever I try to validate this file by loading it into
XmlValidatingReader, but I keep getting error saying.
"System.Xml.Schema.XmlSchemaException: The attribute targetNamespace
does not match the designated namespace URI. "
When I try to validate from Visual Studio .net environment I get the
following error. "Visual Studio could not locate a schema for this
document. Validation can only ensure this is a well formed XML
document and cannot validate the data against a schema.
"
And when I try to use MSXML4, it would load the file fine, but it is
not validating the xml file.
I tried couple of ways by hard coding schema path, copying schema
files and xml files in the same directories but none of those worked.
However when I validate the same xml file in xml spy, it validates
with out any errors. Is there any thing that I am missing over here.
Any kind of help is greatly appreciated.
Thank you.
murali.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
