Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Validating XML against Schema

From: "Priscilla Walmsley" <nospam@-------.--->
To: NULL
Date: 7/2/2004 11:32:00 AM
Hi,

There are several problems that I see at first glance:

1. You need to prefix AccountUpdate with "tmpGlobals:" - otherwise the
namespace declaration does nothing.

2. Your xsi:schemaLocation attribute should say ..../tmpGlobals instead of
.../globals.  The namespaces have to match exactly.

3. The namespace specified in your xs:import statement in account.xsd must
match the target namespace of the schema you are importing.  So, it must use
www.temp.com instead of www.talgov.com.

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema  /  XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

"maddalimurali" <maddalimurali@y...> wrote in message
news:d3ecf31.0407020556.1339748@p......
> 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.




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent