473,597 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="ProductTy pe">
<xsd:sequence >
<xsd:element name="Type" type="xsd:strin g"/>
</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"
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="PersonTyp e">
<xsd:sequence >
<xsd:element name="Name" type="xsd:strin g"/>
<xsd:element name="SSN" type="xsd:strin g"/>
</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="htt p://www.product.org "
xmlns="http://www.company.org "
elementFormDefa ult="qualified" >
<xsd:element name="Company">
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="Person"
type="per:Perso nType"
maxOccurs="unbo unded"/>
<xsd:element name="Product"
type="prod:Prod uctType"
maxOccurs="unbo unded"/>
</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 ConsoleApplicat ion5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEvent Handler
eventHandler = new ValidationEvent Handler
(Class1.ShowCom pileErrors);
XmlSchemaCollec tion
myschemacoll = new XmlSchemaCollec tion();
XmlValidatingRe ader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c: \Staging\UDG\Ph ase Two\Technical
Design\CompTest .xml", FileMode.Open);
//Load the
XmlValidatingRe ader.
vr = new
XmlValidatingRe ader(stream, XmlNodeType.Ele ment, null);

//Add the schemas
to the XmlSchemaCollec tion object.
myschemacoll.Ad d
("http://www.company.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\company. xsd");
myschemacoll.Ad d
("http://www.person.org" , @"c:\Staging\UD G\Phase
Two\Technical Design\person.x sd");
myschemacoll.Ad d
("http://www.product.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\product. xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationTy pe
= ValidationType. Schema;

vr.ValidationEv entHandler += eventHandler;
while (vr.Read())

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

public static void
ShowCompileErro rs(object sender, ValidationEvent Args args)
{
Console.WriteLi ne
("Validation Error: {0}", args.Message);
}
}
}

}
Nov 12 '05 #1
4 1672
Hi,

If you don't want to qualify the Person and Product elements, you should use
elementFormDefa ult="unqualifie d" 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*******@cool groups.com> wrote in message
news:fd******** *************** *******@news.sc biz.com...
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 "
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="ProductTy pe">
<xsd:sequence >
<xsd:element name="Type" type="xsd:strin g"/>
</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"
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="PersonTyp e">
<xsd:sequence >
<xsd:element name="Name" type="xsd:strin g"/>
<xsd:element name="SSN" type="xsd:strin g"/>
</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="htt p://www.product.org "
xmlns="http://www.company.org "
elementFormDefa ult="qualified" >
<xsd:element name="Company">
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="Person"
type="per:Perso nType"
maxOccurs="unbo unded"/>
<xsd:element name="Product"
type="prod:Prod uctType"
maxOccurs="unbo unded"/>
</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 ConsoleApplicat ion5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEvent Handler
eventHandler = new ValidationEvent Handler
(Class1.ShowCom pileErrors);
XmlSchemaCollec tion
myschemacoll = new XmlSchemaCollec tion();
XmlValidatingRe ader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c: \Staging\UDG\Ph ase Two\Technical
Design\CompTest .xml", FileMode.Open);
//Load the
XmlValidatingRe ader.
vr = new
XmlValidatingRe ader(stream, XmlNodeType.Ele ment, null);

//Add the schemas
to the XmlSchemaCollec tion object.
myschemacoll.Ad d
("http://www.company.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\company. xsd");
myschemacoll.Ad d
("http://www.person.org" , @"c:\Staging\UD G\Phase
Two\Technical Design\person.x sd");
myschemacoll.Ad d
("http://www.product.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\product. xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationTy pe
= ValidationType. Schema;

vr.ValidationEv entHandler += eventHandler;
while (vr.Read())

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

public static void
ShowCompileErro rs(object sender, ValidationEvent Args args)
{
Console.WriteLi ne
("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
SchemaCollectio n 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******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

If you don't want to qualify the Person and Product elements, you should use elementFormDefa ult="unqualifie d" 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*******@cool groups.com> wrote in message
news:fd******** *************** *******@news.sc biz.com...
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 "
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="ProductTy pe">
<xsd:sequence >
<xsd:element name="Type" type="xsd:strin g"/>
</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"
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="PersonTyp e">
<xsd:sequence >
<xsd:element name="Name" type="xsd:strin g"/>
<xsd:element name="SSN" type="xsd:strin g"/>
</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="htt p://www.product.org "
xmlns="http://www.company.org "
elementFormDefa ult="qualified" >
<xsd:element name="Company">
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="Person"
type="per:Perso nType"
maxOccurs="unbo unded"/>
<xsd:element name="Product"
type="prod:Prod uctType"
maxOccurs="unbo unded"/>
</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 ConsoleApplicat ion5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEvent Handler
eventHandler = new ValidationEvent Handler
(Class1.ShowCom pileErrors);
XmlSchemaCollec tion
myschemacoll = new XmlSchemaCollec tion();
XmlValidatingRe ader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c: \Staging\UDG\Ph ase Two\Technical
Design\CompTest .xml", FileMode.Open);
//Load the
XmlValidatingRe ader.
vr = new
XmlValidatingRe ader(stream, XmlNodeType.Ele ment, null);

//Add the schemas
to the XmlSchemaCollec tion object.
myschemacoll.Ad d
("http://www.company.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\company. xsd");
myschemacoll.Ad d
("http://www.person.org" , @"c:\Staging\UD G\Phase
Two\Technical Design\person.x sd");
myschemacoll.Ad d
("http://www.product.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\product. xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationTy pe
= ValidationType. Schema;

vr.ValidationEv entHandler += eventHandler;
while (vr.Read())

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

public static void
ShowCompileErro rs(object sender, ValidationEvent Args args)
{
Console.WriteLi ne
("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**********@m sbinfo.com> wrote in message
news:uI******** ******@tk2msftn gp13.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
SchemaCollectio n 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******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

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

use
elementFormDefa ult="unqualifie d" 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*******@cool groups.com> wrote in message
news:fd******** *************** *******@news.sc biz.com...
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 "
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="ProductTy pe">
<xsd:sequence >
<xsd:element name="Type" type="xsd:strin g"/>
</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"
elementFormDefa ult="unqualifie d">
<xsd:complexTyp e name="PersonTyp e">
<xsd:sequence >
<xsd:element name="Name" type="xsd:strin g"/>
<xsd:element name="SSN" type="xsd:strin g"/>
</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="htt p://www.product.org "
xmlns="http://www.company.org "
elementFormDefa ult="qualified" >
<xsd:element name="Company">
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="Person"
type="per:Perso nType"
maxOccurs="unbo unded"/>
<xsd:element name="Product"
type="prod:Prod uctType"
maxOccurs="unbo unded"/>
</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 ConsoleApplicat ion5
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the
application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ValidationEvent Handler
eventHandler = new ValidationEvent Handler
(Class1.ShowCom pileErrors);
XmlSchemaCollec tion
myschemacoll = new XmlSchemaCollec tion();
XmlValidatingRe ader vr;
FileStream stream;
try
{
stream = new
FileStream(@"c: \Staging\UDG\Ph ase Two\Technical
Design\CompTest .xml", FileMode.Open);
//Load the
XmlValidatingRe ader.
vr = new
XmlValidatingRe ader(stream, XmlNodeType.Ele ment, null);

//Add the schemas
to the XmlSchemaCollec tion object.
myschemacoll.Ad d
("http://www.company.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\company. xsd");
myschemacoll.Ad d
("http://www.person.org" , @"c:\Staging\UD G\Phase
Two\Technical Design\person.x sd");
myschemacoll.Ad d
("http://www.product.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\product. xsd");

vr.Schemas.Add
(myschemacoll);

vr.ValidationTy pe
= ValidationType. Schema;

vr.ValidationEv entHandler += eventHandler;
while (vr.Read())

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

public static void
ShowCompileErro rs(object sender, ValidationEvent Args args)
{
Console.WriteLi ne
("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.Ad d("http://www.person.org" , @"c:\Staging\pe rson.xsd");
myschemacoll.Ad d("http://www.product.org ", @"c:\Staging\pr oduct.xsd");

myschemacoll.Ad d("http://www.company.org ", @"c:\Staging\co mpany.xsd");

If I add like this:

myschemacoll.Ad d("http://www.company.org ", @"c:\Staging\UD G\Phase
Two\Technical Design\company. xsd");

myschemacoll.Ad d("http://www.person.org" , @"c:\Staging\UD G\Phase
Two\Technical Design\person.x sd");

myschemacoll.Ad d("http://www.product.org ", @"c:\Staging\UD G\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="htt p://www.product.org "

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

elementFormDefa ult="unqualifie d">
<xsd:import namespace="http ://www.person.org" />

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

<xsd:complexTyp e>

<xsd:sequence >

<xsd:element name="Person" type="per:Perso nType"

maxOccurs="unbo unded"/>

<xsd:element name="Product" type="prod:Prod uctType"

maxOccurs="unbo unded"/>

</xsd:sequence>

</xsd:complexType >

</xsd:element>

</xsd:schema>



"Priscilla Walmsley" <no****@datypic .com> wrote in message
news:eD******** *****@tk2msftng p13.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**********@m sbinfo.com> wrote in message
news:uI******** ******@tk2msftn gp13.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
SchemaCollectio n 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******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

If you don't want to qualify the Person and Product elements, you should
use
elementFormDefa ult="unqualifie d" 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*******@cool groups.com> wrote in message
news:fd******** *************** *******@news.sc biz.com...
> 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 "
> elementFormDefa ult="unqualifie d">
> <xsd:complexTyp e name="ProductTy pe">
> <xsd:sequence >
> <xsd:element name="Type" type="xsd:strin g"/>
> </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"
> elementFormDefa ult="unqualifie d">
> <xsd:complexTyp e name="PersonTyp e">
> <xsd:sequence >
> <xsd:element name="Name" type="xsd:strin g"/>
> <xsd:element name="SSN" type="xsd:strin g"/>
> </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="htt p://www.product.org "
> xmlns="http://www.company.org "
> elementFormDefa ult="qualified" >
> <xsd:element name="Company">
> <xsd:complexTyp e>
> <xsd:sequence >
> <xsd:element name="Person"
> type="per:Perso nType"
> maxOccurs="unbo unded"/>
> <xsd:element name="Product"
> type="prod:Prod uctType"
> maxOccurs="unbo unded"/>
> </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 ConsoleApplicat ion5
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class Class1
> {
> /// <summary>
> /// The main entry point for the
> application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> ValidationEvent Handler
> eventHandler = new ValidationEvent Handler
> (Class1.ShowCom pileErrors);
> XmlSchemaCollec tion
> myschemacoll = new XmlSchemaCollec tion();
> XmlValidatingRe ader vr;
> FileStream stream;
> try
> {
> stream = new
> FileStream(@"c: \Staging\UDG\Ph ase Two\Technical
> Design\CompTest .xml", FileMode.Open);
> //Load the
> XmlValidatingRe ader.
> vr = new
> XmlValidatingRe ader(stream, XmlNodeType.Ele ment, null);
>
> //Add the schemas
> to the XmlSchemaCollec tion object.
> myschemacoll.Ad d
> ("http://www.company.org ", @"c:\Staging\UD G\Phase
> Two\Technical Design\company. xsd");
> myschemacoll.Ad d
> ("http://www.person.org" , @"c:\Staging\UD G\Phase
> Two\Technical Design\person.x sd");
> myschemacoll.Ad d
> ("http://www.product.org ", @"c:\Staging\UD G\Phase
> Two\Technical Design\product. xsd");
>
> vr.Schemas.Add
> (myschemacoll);
>
> vr.ValidationTy pe
> = ValidationType. Schema;
>
> vr.ValidationEv entHandler += eventHandler;
> while (vr.Read())
>
> {//Console.WriteLi ne(" :: " + vr.Name);
> }
> Console.WriteLi ne
> ("Validation completed");
> }
> //This code
> catches any XML exceptions.
> catch (XmlException XmlExp)
> {
> Console.WriteLi ne
> ("XML ERROR: " + XmlExp.Message) ;
> }
> //This code
> catches any XML schema exceptions.
> catch (XmlSchemaExcep tion
> XmlSchemaExp)
> {
> Console.WriteLi ne
> ("SCHEMA ERROR: " + XmlSchemaExp.Me ssage);
>
>
> }
> //This code
> catches any standard exceptions.
> catch (Exception
> GeneralExp)
> {
> Console.WriteLi ne
> (GeneralExp.Mes sage);
> }
> finally
> {
> //Clean up.
> Console.Read();
> vr = null;
> myschemacoll =
> null;
> stream = null;
> }
>
>
> }
>
> public static void
> ShowCompileErro rs(object sender, ValidationEvent Args args)
> {
> Console.WriteLi ne
> ("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
2223
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 some of these master complex and simple types. This I believe will assist me in transforming between the master schema and the other smaller schemas that contain a subset of the elements in the master schema. I understand that I can import an...
3
6493
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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07162002.asp) but I don't want clients to have to add two web references and then manually have to edit the proxy classes. After doing some searching I found that putting references to multiple web services in a .disco...
5
5388
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 separate files for ease of maintainability. These schemas are all part of the same namespace. When defining a web service that access more than one of these entities, the wsdl file generated by BEA contains multiple schema elements with the same...
3
1562
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. there is only one call to the Send method. The problem occurs with and also without a CDO.Configuration set to the Message. When I test the form from my computer, it acts normally, sending only one message, and I receive only one message;...
0
1820
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 single common schema in the wsdl. The issue is complicated because I have several wsdls with several common and unique schemas. As an example serviceA_Ports.wsdl imports a commonServiceTypes.Xml, commonFaultTypes.xml, and serviceA.xml ...
3
11679
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 BEFORE: strCurrency = oSOAP.eServeSearch(CSTR(Request.Form("T1"))) until the WSDL file changed to have more <element name> T1 is just a field that accepts a STRING
5
4946
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
6236
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5384
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
2233
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. The problem I have is the first record gets processed fine where as the second record always; reason being the EAI expects it to be a seperate call Though I am creating/reseting a new service everytime within the foreach loop the data seems to be...
0
7893
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8259
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6698
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.