472,971 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Problems with XmlSchema name mangling XmlSchemaSet compilation

Hello Xml Gurus,

I'm trying to build an XML schema in memory using the System.Xml.XmlSchema
namespace objects, validate it, and then write it to a file. The problem
I'm facing is that XmlSchema.Write() is changing

<xsd:element minOccurs="1" name="AccountId" type="s-xsd:primarykey" />

to be

<xsd:element minOccurs="1" name="AccountId" xmlns:q1="s-xsd"
type="q1:primarykey" />

and I am also getting the following error messages by XmlSchemaSet.Compile()

Namespace 's-xsd' is not available to be referenced in this schema.
Type 's-xsd:primarykey' is not declared.
--------------------------------------------------------------------------------
My code basically looks like this
--------------------------------------------------------------------------------

XmlSchema schema = new XmlSchema();
schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
schema.ElementFormDefault = XmlSchemaForm.Qualified;
schema.TargetNamespace = "http://www.baseUri.com/sxml/1.0";
schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
schema.Namespaces.Add("s-xml", "http://www.baseUri.com/sxml/1.0");
schema.Namespaces.Add("s-xsd", "http://www.baseUri.com/sxsd/1.0");

// <xsd:import...
XmlSchemaImport import = new XmlSchemaImport();
schema.Includes.Add(import);
import.Namespace = "http://www.baseUri.com/sxsd/1.0";
import.SchemaLocation = "s-xsd.xsd";

// <xsd:complexType...
XmlSchemaComplex complexType = new XmlSchemaComplexType();
schema.Items.Add(complexType);
complexType.Name = "Account";

// <xsd:sequence>
XmlSchemaSequence sequence = new XmlSchemaSequence();
complexType.Particle = sequence;

// <xsd:element...
XmlSchemaElement element = new XmlSchemaElement();
element.Name = "AccountId";
element.MinOccurs = 1;
element.MaxOccurs = 1;
element.SchemaType = new XmlQualifiedName("primarykey", "s-xsd");

// Compile schema and validate
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new
ValidationEventHandler(schemaSet_ValidationEventHa ndler);
schemaSet.Add(schema);
schemaSet.Compile();

// Write compiled schemas to output
foreach (XmlSchema compiledSchema in schemaSet.Schemas())
{
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("s-xml", "http://www.baseUri.com/sxml/1.0");
nsmgr.AddNamespace("s-xsd", "http://www.baseUri.com/sxsd/1.0");
compiledSchema.Write(Console.Out);
}

--------------------------------------------------------------------------------
And the output looks like this:

(Note that there are 2 schemas. The first is the one I
created through code, and the second is the one
referenced by the first)
--------------------------------------------------------------------------------

<?xml version="1.0" encoding="IBM437"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.baseUri.com/sxml/1.0"
xmlns:s-xml="http://www.baseUri.com/sxml/1.0"
xmlns:s-xsd="http://www.baseUri.com/sxsd/1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import schemaLocation="s-xsd.xsd"
namespace="http://www.baseUri.com/sxsd/1.0" />
<xsd:complexType name="queue">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" name="queueid"
xmlns:q1="s-xsd" type="q1:primarykey" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

<?xml version="1.0" encoding="IBM437"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.baseUri.com/sxsd/1.0"
xmlns:s-xsd="http://www.baseUri.com/sxsd/1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="primarykey">
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
</xsd:schema>

Can someone please tell me what I'm doing wrong? Is the
System.Xml.XmlSchema more pain than it's worth?

Thanks,

Ryan Parlee


Nov 30 '07 #1
1 3965
Took a break then came back and quickly realized my stupid mistake...
element.SchemaType = new XmlQualifiedName("primarykey", "s-xsd");
should have been
element.SchemaType = new XmlQualifiedName("primarykey",
"http://www.baseUri.com/sxsd/1.0");
That took care of both the aliasing (which now makes sense because it had to
use local scope to override a global namespace naming collision) and the
errors output from XmlSchemaSet.Compile()
-Ryan

"Ryan" <pa*****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hello Xml Gurus,

I'm trying to build an XML schema in memory using the System.Xml.XmlSchema
namespace objects, validate it, and then write it to a file. The problem
I'm facing is that XmlSchema.Write() is changing

<xsd:element minOccurs="1" name="AccountId" type="s-xsd:primarykey" />

to be

<xsd:element minOccurs="1" name="AccountId" xmlns:q1="s-xsd"
type="q1:primarykey" />

and I am also getting the following error messages by
XmlSchemaSet.Compile()

Namespace 's-xsd' is not available to be referenced in this schema.
Type 's-xsd:primarykey' is not declared.
--------------------------------------------------------------------------------
My code basically looks like this
--------------------------------------------------------------------------------

XmlSchema schema = new XmlSchema();
schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
schema.ElementFormDefault = XmlSchemaForm.Qualified;
schema.TargetNamespace = "http://www.baseUri.com/sxml/1.0";
schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
schema.Namespaces.Add("s-xml", "http://www.baseUri.com/sxml/1.0");
schema.Namespaces.Add("s-xsd", "http://www.baseUri.com/sxsd/1.0");

// <xsd:import...
XmlSchemaImport import = new XmlSchemaImport();
schema.Includes.Add(import);
import.Namespace = "http://www.baseUri.com/sxsd/1.0";
import.SchemaLocation = "s-xsd.xsd";

// <xsd:complexType...
XmlSchemaComplex complexType = new XmlSchemaComplexType();
schema.Items.Add(complexType);
complexType.Name = "Account";

// <xsd:sequence>
XmlSchemaSequence sequence = new XmlSchemaSequence();
complexType.Particle = sequence;

// <xsd:element...
XmlSchemaElement element = new XmlSchemaElement();
element.Name = "AccountId";
element.MinOccurs = 1;
element.MaxOccurs = 1;
element.SchemaType = new XmlQualifiedName("primarykey", "s-xsd");

// Compile schema and validate
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new
ValidationEventHandler(schemaSet_ValidationEventHa ndler);
schemaSet.Add(schema);
schemaSet.Compile();

// Write compiled schemas to output
foreach (XmlSchema compiledSchema in schemaSet.Schemas())
{
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("s-xml", "http://www.baseUri.com/sxml/1.0");
nsmgr.AddNamespace("s-xsd", "http://www.baseUri.com/sxsd/1.0");
compiledSchema.Write(Console.Out);
}

--------------------------------------------------------------------------------
And the output looks like this:

(Note that there are 2 schemas. The first is the one I
created through code, and the second is the one
referenced by the first)
--------------------------------------------------------------------------------

<?xml version="1.0" encoding="IBM437"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.baseUri.com/sxml/1.0"
xmlns:s-xml="http://www.baseUri.com/sxml/1.0"
xmlns:s-xsd="http://www.baseUri.com/sxsd/1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import schemaLocation="s-xsd.xsd"
namespace="http://www.baseUri.com/sxsd/1.0" />
<xsd:complexType name="queue">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" name="queueid"
xmlns:q1="s-xsd" type="q1:primarykey" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

<?xml version="1.0" encoding="IBM437"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.baseUri.com/sxsd/1.0"
xmlns:s-xsd="http://www.baseUri.com/sxsd/1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="primarykey">
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
</xsd:schema>

Can someone please tell me what I'm doing wrong? Is the
System.Xml.XmlSchema more pain than it's worth?

Thanks,

Ryan Parlee


Nov 30 '07 #2

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

Similar topics

0
by: Michiel | last post by:
Hello, I am not sure this is the right place to ask. I tried the ZSI mailing list, but got no response there. My goal is to write some web services with ZSI to be used by a client written in...
1
by: Tim Slattery | last post by:
Does the C++ language standard mandate a particular name-mangling method? I'm trying to use the Entrust toolkit to create a C++ program that encrypts and decrypts files. Entrust supplies header...
1
by: Linus | last post by:
Hi, I'm having problems with some very simple deserialization code and would appreciate it very much if I could get some help here. The following is the code:...
2
by: Alex Shirshov | last post by:
Hello, All! It seems the bug (http://groups.google.com/groups?hl=ru&lr=&ie=UTF-8&threadm=a53b01c28a00%242 08bc860%2439ef2ecf%40TKMSFTNGXA08&rnum=8&prev=/groups%3Fq%3DschemaLocation%2...
4
by: Igor Koretsky | last post by:
Hi. Using VB.Net System.Xml 1.0 SchemaCollection Object I am getting an error when trying to add ‘Schema A’ to the SchemaCollection. Here are my schema files..
7
by: seema | last post by:
I have problem compiling this program using GCC(g++) //bye.h --header file #ifndef BYE_H #define BYE_H void display(); #endif //bye.C -------- Source #include "bye.h"
2
by: MyndPhlyp | last post by:
I am attempting to write a DLL to maintain an XML file. It creates its own XSD as an XmlSchema (or even a compiled member of an XmlSchemaSet, if necessary). I don't want to write an XSD to disk....
0
by: Default User | last post by:
I work on creating test cases for a SOAP-based set of servers, using soapUI. I received and updated set of WSDL and schema files, and when I made new tests and mock server operations, all of the...
14
by: Megalo | last post by:
why not make "name mangling" of C++ standard so should be possible to call the classes and the functions of C++ from other C++ compiler thanks
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.