473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Multiple schemas, one xml doc

When I use the schema collection to apply many schemas to
one XML instance document, I get an error if I do not
qualify every element with the appropriate namespace.

Both the W3C site and this article
(http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply
that I can submit an XML instance without having to
qualify each element.

How do I accomplish this while still using .Net & the
Validating Reader?

Thanks,

Raj (Example code follows)
ra****************@yahoo.com

Example:

XSD Product
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Person
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Company
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace=”http://www.company.org”
xmlns:per="http://www.person.org"
xmlns:prod="http://www.product.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person"
type="per:PersonType"
maxOccurs="unbounded"/>
<xsd:element name="Product"
type="prod:ProductType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

I should be able to submit XML like the following (note:
only one element has namespace qualification -> to the
parent XSD file):

<?xml version="1.0"?>
<c:Company xmlns:c="http://www.company.org">
<Person>
<Name>John Doe</Name>
<SSN>123-45-6789</SSN>
</Person>
<Product>
<Type>Widget</Type>
</Product>
</c:Company>

My code:

namespace ConsoleApplication5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEventHandler
eventHandler = new ValidationEventHandler
(Class1.ShowCompileErrors);
XmlSchemaCollection
myschemacoll = new XmlSchemaCollection();
XmlValidatingReader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c:\Staging\UDG\Phase Two\Technical
Design\CompTest.xml", FileMode.Open);
//Load the
XmlValidatingReader.
vr = new
XmlValidatingReader(stream, XmlNodeType.Element, null);

//Add the schemas
to the XmlSchemaCollection object.
myschemacoll.Add
("http://www.company.org", @"c:\Staging\UDG\Phase
Two\Technical Design\company.xsd");
myschemacoll.Add
("http://www.person.org", @"c:\Staging\UDG\Phase
Two\Technical Design\person.xsd");
myschemacoll.Add
("http://www.product.org", @"c:\Staging\UDG\Phase
Two\Technical Design\product.xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationType
= ValidationType.Schema;

vr.ValidationEventHandler += eventHandler;
while (vr.Read())

{//Console.WriteLine(" :: " + vr.Name);
}
Console.WriteLine
("Validation completed");
}
//This code
catches any XML exceptions.
catch (XmlException XmlExp)
{
Console.WriteLine
("XML ERROR: " + XmlExp.Message);
}
//This code
catches any XML schema exceptions.
catch (XmlSchemaException
XmlSchemaExp)
{
Console.WriteLine
("SCHEMA ERROR: " + XmlSchemaExp.Message);
}
//This code
catches any standard exceptions.
catch (Exception
GeneralExp)
{
Console.WriteLine
(GeneralExp.Message);
}
finally
{
//Clean up.
Console.Read();
vr = null;
myschemacoll =
null;
stream = null;
}
}

public static void
ShowCompileErrors(object sender, ValidationEventArgs args)
{
Console.WriteLine
("Validation Error: {0}", args.Message);
}
}
}

}
Nov 12 '05 #1
4 1664
Hi,

If you don't want to qualify the Person and Product elements, you should use
elementFormDefault="unqualified" in your Company schema. Currently, you
have it set to qualified, meaning that locally declared elements (namely
Person and Product) should be qualified.

Also, you need to use two xsd:import in your Company schema for the person
and product namespaces.

Hope that helps,
Priscilla

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

<an*******@coolgroups.com> wrote in message
news:fd******************************@news.scbiz.c om...
When I use the schema collection to apply many schemas to
one XML instance document, I get an error if I do not
qualify every element with the appropriate namespace.

Both the W3C site and this article
(http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply
that I can submit an XML instance without having to
qualify each element.

How do I accomplish this while still using .Net & the
Validating Reader?

Thanks,

Raj (Example code follows)
ra****************@yahoo.com

Example:

XSD Product
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Person
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Company
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns:per="http://www.person.org"
xmlns:prod="http://www.product.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person"
type="per:PersonType"
maxOccurs="unbounded"/>
<xsd:element name="Product"
type="prod:ProductType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

I should be able to submit XML like the following (note:
only one element has namespace qualification -> to the
parent XSD file):

<?xml version="1.0"?>
<c:Company xmlns:c="http://www.company.org">
<Person>
<Name>John Doe</Name>
<SSN>123-45-6789</SSN>
</Person>
<Product>
<Type>Widget</Type>
</Product>
</c:Company>

My code:

namespace ConsoleApplication5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEventHandler
eventHandler = new ValidationEventHandler
(Class1.ShowCompileErrors);
XmlSchemaCollection
myschemacoll = new XmlSchemaCollection();
XmlValidatingReader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c:\Staging\UDG\Phase Two\Technical
Design\CompTest.xml", FileMode.Open);
//Load the
XmlValidatingReader.
vr = new
XmlValidatingReader(stream, XmlNodeType.Element, null);

//Add the schemas
to the XmlSchemaCollection object.
myschemacoll.Add
("http://www.company.org", @"c:\Staging\UDG\Phase
Two\Technical Design\company.xsd");
myschemacoll.Add
("http://www.person.org", @"c:\Staging\UDG\Phase
Two\Technical Design\person.xsd");
myschemacoll.Add
("http://www.product.org", @"c:\Staging\UDG\Phase
Two\Technical Design\product.xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationType
= ValidationType.Schema;

vr.ValidationEventHandler += eventHandler;
while (vr.Read())

{//Console.WriteLine(" :: " + vr.Name);
}
Console.WriteLine
("Validation completed");
}
//This code
catches any XML exceptions.
catch (XmlException XmlExp)
{
Console.WriteLine
("XML ERROR: " + XmlExp.Message);
}
//This code
catches any XML schema exceptions.
catch (XmlSchemaException
XmlSchemaExp)
{
Console.WriteLine
("SCHEMA ERROR: " + XmlSchemaExp.Message);
}
//This code
catches any standard exceptions.
catch (Exception
GeneralExp)
{
Console.WriteLine
(GeneralExp.Message);
}
finally
{
//Clean up.
Console.Read();
vr = null;
myschemacoll =
null;
stream = null;
}
}

public static void
ShowCompileErrors(object sender, ValidationEventArgs args)
{
Console.WriteLine
("Validation Error: {0}", args.Message);
}
}
}

}

Nov 12 '05 #2
raj
Pricilla,

Thank you, that worked... What I'd like to do, however, is have the .net
code in charge of selecting the appropriate set of schemas instead of
hardcoding the references with an <import>. The fact that there is a
SchemaCollection implies I should be able to do this -- without having to
qualify the elements as in the Msoft example. What am I missing?

Your solution provides a viable workaround, though, so thanks :)

Cheers,

Raj

"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:eg****************@TK2MSFTNGP12.phx.gbl...
Hi,

If you don't want to qualify the Person and Product elements, you should use elementFormDefault="unqualified" in your Company schema. Currently, you
have it set to qualified, meaning that locally declared elements (namely
Person and Product) should be qualified.

Also, you need to use two xsd:import in your Company schema for the person
and product namespaces.

Hope that helps,
Priscilla

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

<an*******@coolgroups.com> wrote in message
news:fd******************************@news.scbiz.c om...
When I use the schema collection to apply many schemas to
one XML instance document, I get an error if I do not
qualify every element with the appropriate namespace.

Both the W3C site and this article
(http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply
that I can submit an XML instance without having to
qualify each element.

How do I accomplish this while still using .Net & the
Validating Reader?

Thanks,

Raj (Example code follows)
ra****************@yahoo.com

Example:

XSD Product
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Person
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Company
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns:per="http://www.person.org"
xmlns:prod="http://www.product.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person"
type="per:PersonType"
maxOccurs="unbounded"/>
<xsd:element name="Product"
type="prod:ProductType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

I should be able to submit XML like the following (note:
only one element has namespace qualification -> to the
parent XSD file):

<?xml version="1.0"?>
<c:Company xmlns:c="http://www.company.org">
<Person>
<Name>John Doe</Name>
<SSN>123-45-6789</SSN>
</Person>
<Product>
<Type>Widget</Type>
</Product>
</c:Company>

My code:

namespace ConsoleApplication5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEventHandler
eventHandler = new ValidationEventHandler
(Class1.ShowCompileErrors);
XmlSchemaCollection
myschemacoll = new XmlSchemaCollection();
XmlValidatingReader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c:\Staging\UDG\Phase Two\Technical
Design\CompTest.xml", FileMode.Open);
//Load the
XmlValidatingReader.
vr = new
XmlValidatingReader(stream, XmlNodeType.Element, null);

//Add the schemas
to the XmlSchemaCollection object.
myschemacoll.Add
("http://www.company.org", @"c:\Staging\UDG\Phase
Two\Technical Design\company.xsd");
myschemacoll.Add
("http://www.person.org", @"c:\Staging\UDG\Phase
Two\Technical Design\person.xsd");
myschemacoll.Add
("http://www.product.org", @"c:\Staging\UDG\Phase
Two\Technical Design\product.xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationType
= ValidationType.Schema;

vr.ValidationEventHandler += eventHandler;
while (vr.Read())

{//Console.WriteLine(" :: " + vr.Name);
}
Console.WriteLine
("Validation completed");
}
//This code
catches any XML exceptions.
catch (XmlException XmlExp)
{
Console.WriteLine
("XML ERROR: " + XmlExp.Message);
}
//This code
catches any XML schema exceptions.
catch (XmlSchemaException
XmlSchemaExp)
{
Console.WriteLine
("SCHEMA ERROR: " + XmlSchemaExp.Message);
}
//This code
catches any standard exceptions.
catch (Exception
GeneralExp)
{
Console.WriteLine
(GeneralExp.Message);
}
finally
{
//Clean up.
Console.Read();
vr = null;
myschemacoll =
null;
stream = null;
}
}

public static void
ShowCompileErrors(object sender, ValidationEventArgs args)
{
Console.WriteLine
("Validation Error: {0}", args.Message);
}
}
}

}


Nov 12 '05 #3
Hi Raj,
The main purpose of an xsd:import is just to record a dependency on another
namespace, not necessarily to import another schema document. As such, the
schemaLocation attribute on an xsd:import is optional; only the namespace
attribute is required.

So you could try specifying just the namespace in your xsd:import, and use
the code to specify the schema locations for each namespace. I haven't
tried this in .net, but I would think it would work.

Hope that helps,
Priscilla

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

"raj" <ra**********@msbinfo.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
Pricilla,

Thank you, that worked... What I'd like to do, however, is have the .net
code in charge of selecting the appropriate set of schemas instead of
hardcoding the references with an <import>. The fact that there is a
SchemaCollection implies I should be able to do this -- without having to
qualify the elements as in the Msoft example. What am I missing?

Your solution provides a viable workaround, though, so thanks :)

Cheers,

Raj

"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:eg****************@TK2MSFTNGP12.phx.gbl...
Hi,

If you don't want to qualify the Person and Product elements, you should

use
elementFormDefault="unqualified" in your Company schema. Currently, you have it set to qualified, meaning that locally declared elements (namely
Person and Product) should be qualified.

Also, you need to use two xsd:import in your Company schema for the person and product namespaces.

Hope that helps,
Priscilla

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

<an*******@coolgroups.com> wrote in message
news:fd******************************@news.scbiz.c om...
When I use the schema collection to apply many schemas to
one XML instance document, I get an error if I do not
qualify every element with the appropriate namespace.

Both the W3C site and this article
(http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply
that I can submit an XML instance without having to
qualify each element.

How do I accomplish this while still using .Net & the
Validating Reader?

Thanks,

Raj (Example code follows)
ra****************@yahoo.com

Example:

XSD Product
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Person
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

XSD Company
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns:per="http://www.person.org"
xmlns:prod="http://www.product.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person"
type="per:PersonType"
maxOccurs="unbounded"/>
<xsd:element name="Product"
type="prod:ProductType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

I should be able to submit XML like the following (note:
only one element has namespace qualification -> to the
parent XSD file):

<?xml version="1.0"?>
<c:Company xmlns:c="http://www.company.org">
<Person>
<Name>John Doe</Name>
<SSN>123-45-6789</SSN>
</Person>
<Product>
<Type>Widget</Type>
</Product>
</c:Company>

My code:

namespace ConsoleApplication5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEventHandler
eventHandler = new ValidationEventHandler
(Class1.ShowCompileErrors);
XmlSchemaCollection
myschemacoll = new XmlSchemaCollection();
XmlValidatingReader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c:\Staging\UDG\Phase Two\Technical
Design\CompTest.xml", FileMode.Open);
//Load the
XmlValidatingReader.
vr = new
XmlValidatingReader(stream, XmlNodeType.Element, null);

//Add the schemas
to the XmlSchemaCollection object.
myschemacoll.Add
("http://www.company.org", @"c:\Staging\UDG\Phase
Two\Technical Design\company.xsd");
myschemacoll.Add
("http://www.person.org", @"c:\Staging\UDG\Phase
Two\Technical Design\person.xsd");
myschemacoll.Add
("http://www.product.org", @"c:\Staging\UDG\Phase
Two\Technical Design\product.xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationType
= ValidationType.Schema;

vr.ValidationEventHandler += eventHandler;
while (vr.Read())

{//Console.WriteLine(" :: " + vr.Name);
}
Console.WriteLine
("Validation completed");
}
//This code
catches any XML exceptions.
catch (XmlException XmlExp)
{
Console.WriteLine
("XML ERROR: " + XmlExp.Message);
}
//This code
catches any XML schema exceptions.
catch (XmlSchemaException
XmlSchemaExp)
{
Console.WriteLine
("SCHEMA ERROR: " + XmlSchemaExp.Message);
}
//This code
catches any standard exceptions.
catch (Exception
GeneralExp)
{
Console.WriteLine
(GeneralExp.Message);
}
finally
{
//Clean up.
Console.Read();
vr = null;
myschemacoll =
null;
stream = null;
}
}

public static void
ShowCompileErrors(object sender, ValidationEventArgs args)
{
Console.WriteLine
("Validation Error: {0}", args.Message);
}
}
}

}



Nov 12 '05 #4
raj
OK, got it.... silly me, I should have tried this from the get go. The
order the schemas are added to the schema collection is important because
the 'Add' aparently does some basic namespace resolution. So in my case,
the schemas must be added like this:

myschemacoll.Add("http://www.person.org", @"c:\Staging\person.xsd");
myschemacoll.Add("http://www.product.org", @"c:\Staging\product.xsd");

myschemacoll.Add("http://www.company.org", @"c:\Staging\company.xsd");

If I add like this:

myschemacoll.Add("http://www.company.org", @"c:\Staging\UDG\Phase
Two\Technical Design\company.xsd");

myschemacoll.Add("http://www.person.org", @"c:\Staging\UDG\Phase
Two\Technical Design\person.xsd");

myschemacoll.Add("http://www.product.org", @"c:\Staging\UDG\Phase
Two\Technical Design\product.xsd");


The first line will immediately trigger an error because the person and
product namespaces cannot be resolved to a specific location (if I don't use
the schemalocation attribute of the xsl:import).

At least that's what I _think_ is happening....

Thanks, Priscilla, for all your help...

Cheers,

Raj

PS: FWIW, this is the final Company.xsl

<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.company.org"

xmlns:per="http://www.person.org"

xmlns:prod="http://www.product.org"

xmlns="http://www.company.org"

elementFormDefault="unqualified">
<xsd:import namespace="http://www.person.org" />

<xsd:import namespace="http://www.product.org" />
<xsd:element name="Company">

<xsd:complexType>

<xsd:sequence>

<xsd:element name="Person" type="per:PersonType"

maxOccurs="unbounded"/>

<xsd:element name="Product" type="prod:ProductType"

maxOccurs="unbounded"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>



"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:eD*************@tk2msftngp13.phx.gbl...
Hi Raj,
The main purpose of an xsd:import is just to record a dependency on another namespace, not necessarily to import another schema document. As such, the schemaLocation attribute on an xsd:import is optional; only the namespace
attribute is required.

So you could try specifying just the namespace in your xsd:import, and use
the code to specify the schema locations for each namespace. I haven't
tried this in .net, but I would think it would work.

Hope that helps,
Priscilla

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

"raj" <ra**********@msbinfo.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
Pricilla,

Thank you, that worked... What I'd like to do, however, is have the ..net
code in charge of selecting the appropriate set of schemas instead of
hardcoding the references with an <import>. The fact that there is a
SchemaCollection implies I should be able to do this -- without having to qualify the elements as in the Msoft example. What am I missing?

Your solution provides a viable workaround, though, so thanks :)

Cheers,

Raj

"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:eg****************@TK2MSFTNGP12.phx.gbl...
Hi,

If you don't want to qualify the Person and Product elements, you should
use
elementFormDefault="unqualified" in your Company schema. Currently,

you have it set to qualified, meaning that locally declared elements
(namely Person and Product) should be qualified.

Also, you need to use two xsd:import in your Company schema for the

person and product namespaces.

Hope that helps,
Priscilla

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

<an*******@coolgroups.com> wrote in message
news:fd******************************@news.scbiz.c om...
> When I use the schema collection to apply many schemas to
> one XML instance document, I get an error if I do not
> qualify every element with the appropriate namespace.
>
> Both the W3C site and this article
> (http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply
> that I can submit an XML instance without having to
> qualify each element.
>
> How do I accomplish this while still using .Net & the
> Validating Reader?
>
> Thanks,
>
> Raj (Example code follows)
> ra****************@yahoo.com
>
> Example:
>
> XSD Product
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.product.org"
> xmlns="http://www.product.org"
> elementFormDefault="unqualified">
> <xsd:complexType name="ProductType">
> <xsd:sequence>
> <xsd:element name="Type" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
>
> XSD Person
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.person.org"
> xmlns="http://www.person.org"
> elementFormDefault="unqualified">
> <xsd:complexType name="PersonType">
> <xsd:sequence>
> <xsd:element name="Name" type="xsd:string"/>
> <xsd:element name="SSN" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
>
> XSD Company
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.company.org"
> xmlns:per="http://www.person.org"
> xmlns:prod="http://www.product.org"
> xmlns="http://www.company.org"
> elementFormDefault="qualified">
> <xsd:element name="Company">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="Person"
> type="per:PersonType"
> maxOccurs="unbounded"/>
> <xsd:element name="Product"
> type="prod:ProductType"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
>
> I should be able to submit XML like the following (note:
> only one element has namespace qualification -> to the
> parent XSD file):
>
> <?xml version="1.0"?>
> <c:Company xmlns:c="http://www.company.org">
> <Person>
> <Name>John Doe</Name>
> <SSN>123-45-6789</SSN>
> </Person>
> <Product>
> <Type>Widget</Type>
> </Product>
> </c:Company>
>
> My code:
>
> namespace ConsoleApplication5
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class Class1
> {
> /// <summary>
> /// The main entry point for the
> application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> ValidationEventHandler
> eventHandler = new ValidationEventHandler
> (Class1.ShowCompileErrors);
> XmlSchemaCollection
> myschemacoll = new XmlSchemaCollection();
> XmlValidatingReader vr;
> FileStream stream;
> try
> {
> stream = new
> FileStream(@"c:\Staging\UDG\Phase Two\Technical
> Design\CompTest.xml", FileMode.Open);
> //Load the
> XmlValidatingReader.
> vr = new
> XmlValidatingReader(stream, XmlNodeType.Element, null);
>
> //Add the schemas
> to the XmlSchemaCollection object.
> myschemacoll.Add
> ("http://www.company.org", @"c:\Staging\UDG\Phase
> Two\Technical Design\company.xsd");
> myschemacoll.Add
> ("http://www.person.org", @"c:\Staging\UDG\Phase
> Two\Technical Design\person.xsd");
> myschemacoll.Add
> ("http://www.product.org", @"c:\Staging\UDG\Phase
> Two\Technical Design\product.xsd");
>
> vr.Schemas.Add
> (myschemacoll);
>
> vr.ValidationType
> = ValidationType.Schema;
>
> vr.ValidationEventHandler += eventHandler;
> while (vr.Read())
>
> {//Console.WriteLine(" :: " + vr.Name);
> }
> Console.WriteLine
> ("Validation completed");
> }
> //This code
> catches any XML exceptions.
> catch (XmlException XmlExp)
> {
> Console.WriteLine
> ("XML ERROR: " + XmlExp.Message);
> }
> //This code
> catches any XML schema exceptions.
> catch (XmlSchemaException
> XmlSchemaExp)
> {
> Console.WriteLine
> ("SCHEMA ERROR: " + XmlSchemaExp.Message);
>
>
> }
> //This code
> catches any standard exceptions.
> catch (Exception
> GeneralExp)
> {
> Console.WriteLine
> (GeneralExp.Message);
> }
> finally
> {
> //Clean up.
> Console.Read();
> vr = null;
> myschemacoll =
> null;
> stream = null;
> }
>
>
> }
>
> public static void
> ShowCompileErrors(object sender, ValidationEventArgs args)
> {
> Console.WriteLine
> ("Validation Error: {0}", args.Message);
> }
> }
> }
>
> }



Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse...
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing types...
5
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
3
by: Chris Baker | last post by:
This is a problem I have been troubleshooting for about 4-6 months. I have an e-mail form on a client's public website that is mis-behaving. It is written in ASP and uses a CDO.Message object. ...
0
by: vihrao | last post by:
I am designing wsdl that uses multiple schemas. I can do this in two ways: 1) use multiple schema imports in one wsdl or 2) use multiple schema imports in to one common schema and then import a...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: vigneshrao | last post by:
Hi, I have been working on a script that loops through multiple records and sends data (one record per call) to a WS. I am supposed to make a new call for each record before sending the data....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.