Hello Xml Gurus,
I'm trying to build an XML schema in memory using the System.Xml.XmlS chema
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:primar ykey" />
and I am also getting the following error messages by XmlSchemaSet.Co mpile()
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.Attribut eFormDefault = XmlSchemaForm.U nqualified;
schema.ElementF ormDefault = XmlSchemaForm.Q ualified;
schema.TargetNa mespace = "http://www.baseUri.com/sxml/1.0";
schema.Namespac es.Add("xsd", "http://www.w3.org/2001/XMLSchema");
schema.Namespac es.Add("s-xml", "http://www.baseUri.com/sxml/1.0");
schema.Namespac es.Add("s-xsd", "http://www.baseUri.com/sxsd/1.0");
// <xsd:import.. .
XmlSchemaImport import = new XmlSchemaImport ();
schema.Includes .Add(import);
import.Namespac e = "http://www.baseUri.com/sxsd/1.0";
import.SchemaLo cation = "s-xsd.xsd";
// <xsd:complexTyp e...
XmlSchemaComple x complexType = new XmlSchemaComple xType();
schema.Items.Ad d(complexType);
complexType.Nam e = "Account";
// <xsd:sequence >
XmlSchemaSequen ce sequence = new XmlSchemaSequen ce();
complexType.Par ticle = sequence;
// <xsd:element. ..
XmlSchemaElemen t element = new XmlSchemaElemen t();
element.Name = "AccountId" ;
element.MinOccu rs = 1;
element.MaxOccu rs = 1;
element.SchemaT ype = new XmlQualifiedNam e("primarykey ", "s-xsd");
// Compile schema and validate
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Valid ationEventHandl er += new
ValidationEvent Handler(schemaS et_ValidationEv entHandler);
schemaSet.Add(s chema);
schemaSet.Compi le();
// Write compiled schemas to output
foreach (XmlSchema compiledSchema in schemaSet.Schem as())
{
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(new NameTable());
nsmgr.AddNamesp ace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamesp ace("s-xml", "http://www.baseUri.com/sxml/1.0");
nsmgr.AddNamesp ace("s-xsd", "http://www.baseUri.com/sxsd/1.0");
compiledSchema. Write(Console.O ut);
}
--------------------------------------------------------------------------------
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="IBM43 7"?>
<xsd:schema attributeFormDe fault="unqualif ied"
elementFormDefa ult="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:complexTyp e name="queue">
<xsd:sequence >
<xsd:element minOccurs="0" maxOccurs="1" name="queueid"
xmlns:q1="s-xsd" type="q1:primar ykey" />
</xsd:sequence>
</xsd:complexType >
</xsd:schema>
<?xml version="1.0" encoding="IBM43 7"?>
<xsd:schema attributeFormDe fault="unqualif ied"
elementFormDefa ult="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:simpleTy pe name="primaryke y">
<xsd:restrictio n base="xsd:strin g" />
</xsd:simpleType>
</xsd:schema>
Can someone please tell me what I'm doing wrong? Is the
System.Xml.XmlS chema more pain than it's worth?
Thanks,
Ryan Parlee 1 4028
Took a break then came back and quickly realized my stupid mistake...
element.SchemaT ype = new XmlQualifiedNam e("primarykey ", "s-xsd");
should have been
element.SchemaT ype = new XmlQualifiedNam e("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.Co mpile()
-Ryan
"Ryan" <pa*****@nospam .nospamwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Hello Xml Gurus,
I'm trying to build an XML schema in memory using the System.Xml.XmlS chema
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:primar ykey" />
and I am also getting the following error messages by
XmlSchemaSet.Co mpile()
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.Attribut eFormDefault = XmlSchemaForm.U nqualified;
schema.ElementF ormDefault = XmlSchemaForm.Q ualified;
schema.TargetNa mespace = "http://www.baseUri.com/sxml/1.0";
schema.Namespac es.Add("xsd", "http://www.w3.org/2001/XMLSchema");
schema.Namespac es.Add("s-xml", "http://www.baseUri.com/sxml/1.0");
schema.Namespac es.Add("s-xsd", "http://www.baseUri.com/sxsd/1.0");
// <xsd:import.. .
XmlSchemaImport import = new XmlSchemaImport ();
schema.Includes .Add(import);
import.Namespac e = "http://www.baseUri.com/sxsd/1.0";
import.SchemaLo cation = "s-xsd.xsd";
// <xsd:complexTyp e...
XmlSchemaComple x complexType = new XmlSchemaComple xType();
schema.Items.Ad d(complexType);
complexType.Nam e = "Account";
// <xsd:sequence >
XmlSchemaSequen ce sequence = new XmlSchemaSequen ce();
complexType.Par ticle = sequence;
// <xsd:element. ..
XmlSchemaElemen t element = new XmlSchemaElemen t();
element.Name = "AccountId" ;
element.MinOccu rs = 1;
element.MaxOccu rs = 1;
element.SchemaT ype = new XmlQualifiedNam e("primarykey ", "s-xsd");
// Compile schema and validate
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Valid ationEventHandl er += new
ValidationEvent Handler(schemaS et_ValidationEv entHandler);
schemaSet.Add(s chema);
schemaSet.Compi le();
// Write compiled schemas to output
foreach (XmlSchema compiledSchema in schemaSet.Schem as())
{
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(new NameTable());
nsmgr.AddNamesp ace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamesp ace("s-xml", "http://www.baseUri.com/sxml/1.0");
nsmgr.AddNamesp ace("s-xsd", "http://www.baseUri.com/sxsd/1.0");
compiledSchema. Write(Console.O ut);
}
--------------------------------------------------------------------------------
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="IBM43 7"?>
<xsd:schema attributeFormDe fault="unqualif ied"
elementFormDefa ult="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:complexTyp e name="queue">
<xsd:sequence >
<xsd:element minOccurs="0" maxOccurs="1" name="queueid"
xmlns:q1="s-xsd" type="q1:primar ykey" />
</xsd:sequence>
</xsd:complexType >
</xsd:schema>
<?xml version="1.0" encoding="IBM43 7"?>
<xsd:schema attributeFormDe fault="unqualif ied"
elementFormDefa ult="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:simpleTy pe name="primaryke y">
<xsd:restrictio n base="xsd:strin g" />
</xsd:simpleType>
</xsd:schema>
Can someone please tell me what I'm doing wrong? Is the
System.Xml.XmlS chema more pain than it's worth?
Thanks,
Ryan Parlee This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 .NET. I'm using ZSI 1.2.7 (this was easy to install on my
Debian system).
I have no problem with functions with parameters and return values
|
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 files defining
their objects and functions, and *.so files (I'm on a Sun Sparc
machine running Solaris) containing the implementation of the
functions.
I'm compiling with the GNU g++ compiler. According to the
|
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:
=========================================================
XmlReader reader = new XmlTextReader("test.xml");
XmlValidatingReader vr = new XmlValidatingReader(reader);
|
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
BXmlSchema%2B.NET%26hl%3Dru%26lr%3D%26ie%3DUTF-8%26selm%3Da53b01c28a00%25242
08bc860%252439ef2ecf%2540TKMSFTNGXA08%26rnum%3D8) wasn't fixed neither in
v1.1 nor in v2.0.
Here is exception
|
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..
| |
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"
|
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. The XML file, on the other hand, will
be disk resident.
System.Data.DataSet wants to read its schema in from an XmlReader, Stream,
TextReader, or file name string.
|
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 ones that had
been working now returned a SOAP fault. The faults look something like:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<soap:Fault>
<soap:Code>
|
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
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |