namespace problem during validation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi !

I have problem with validating of the document with multiple
namespaces. The odd thing is, that my data work O'K when I test it
under XMLSpy but it doesn't work with my C# code.

My first 'main' schema is as follows:
incr2.xsd
----------
<xs:schema targetNamespace="http://vit.volvo.com/dept9272/2004/ESB";
xmlns:p="tnsperson" xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="tnsperson" schemaLocation="incr11.xsd"/>
<xs:element name="record">
<xs:complexType >
<xs:sequence>
<xs:element ref="p:person"/>
<xs:element name="info" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

As you can see, it imports another schema,
incr11.xsd
----------
<xs:schema targetNamespace="tnsperson" xmlns:t = "tnsperson"
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
<xs:complexType name="persontype">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="person" type="t:persontype">
</xs:element>
</xs:schema>

The sample document is here:
sample.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns="http://vit.volvo.com/dept9272/2004/ESB";
xmlns:p="tnsperson" >
<person xmlns="tnsperson">
<firstname>Tom</firstname>
<lastname>Rom</lastname>
<age>22</age>
</person>
<info>x_info</info>
</record>

The error message is as follows:
*****************
The element 'tnsperson:person' has invalid child element
'tnsperson:firstname'. Expected 'firstname'. An error occurred at file
sample.xml, (4, 4).
*****************

I make the validation using the code presented below. The 'filename' is
XML doc filename, 'SchemaURL' xsd filename and TargetNamespace has
http://vit.volvo.com/dept9272/2004/ESB as a value.

reader = new XmlTextReader(filename);
reader.WhitespaceHandling=WhitespaceHandling.None;
// ^^-- to avoid problems when validating indented docs


XmlSchemaCollection xsc = null;
xsc = new XmlSchemaCollection();
xsc.Add(TargetNamespace, SchemaURL);

vreader = new XmlValidatingReader(reader);

vreader.Schemas.Add(xsc);

vreader.ValidationEventHandler += new
ValidationEventHandler(this.ValidationCallback);

while (vreader.Read())
{}

Why the parser expects child element from default namespace, when its
parent is declared as a reference from other namespace ?
Thanks in advance for any help. I'e spent two days browsing and
testing. No luck yet :-(

.



Relevant Pages

  • Re: Flat File Problem
    ... It was the namespace I was using to ... When I debug the orchestration the RecCount variable is null. ... Have you deployed the Biztalk Assembly that contains the property schema ... And you can promote properties from the Header into the message context, ...
    (microsoft.public.biztalk.general)
  • Schema versioning / namespace or no namespace / like root nodes / Pipelines - any ideas?
    ... Namespace Options: Trying to figure out which way to go... ... I'm planning to handle the varying levels of schema content being ... Pipeline component to add this namespace to incoming SAP docs. ... pipeline per assembly-version (since there's no need for the pipeline ...
    (microsoft.public.biztalk.general)
  • Re: Re: Re: SQLXML Namespaces
    ... > namespace, so SQLXML has declared an arbitrary prefix for the ... > the results you can declare any prefix you like and the XML ... >> Your schema must have a default or target namespace ...
    (microsoft.public.sqlserver.xml)
  • Re: The New Roadmap
    ... this is a HUGE advantage if your trying to port a Win32 Delphi ... A namespace is a logical grouping. ... your class then determines the filename you have to give that unit. ... I keep hearing about the huge productivity gains that generics will ...
    (borland.public.delphi.non-technical)
  • Re: Message type conversion from C# object to BizTalk message
    ... Originally I didn't know what you meant, but of course in BizTalk there are ... Properties) when you simply click once on the schema file and have the ... The second namespace is the targetNamespace in the ...
    (microsoft.public.biztalk.general)