You need to put elementFormDefault="qualified" on your incr11.xsd schema.
are in NO namespace. In your sample instance document, they are in the
<tomek.romanowski@gmail.com> wrote in message
news:1123938803.758070.159060@g14g2000cwa.googlegroups.com...
> 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 :-(
>