473,890 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidCastExce ption on adding schema to XmlSchemaCollec tion

che
Hi all,

I am working with XSD for a while using C# objects (
XmlSchemaCollec tion , XmlValidatingRe ader) and have met this
problem:

Current code demonstrates the problem:

<xs:schema ...>

<xs:element name="Parent" type="Parent_Ty pe" />

<xs:complexTy pe name="Parent_Ty pe">
<xs:all>
<xs:element name="Type" type="xs:string " maxOccurs="1" />
</xs:all>
</xs:complexType>

<xs:complexTy pe name="Child_Typ e">
<xs:complexCont ent>
<xs:extension base="Parent_Ty pe"/>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="Child" substitutionGro up="Parent"
type="Child_Typ e" />

<xs:element name="Test">
<xs:complexType >
<xs:all>
<xs:element ref="Parent" minOccurs="0" />
<xs:element name="additiona lElement" type="xs:boolea n" />
</xs:all>
</xs:complexType>
</xs:element>

</xs:schema>

When loading the XSD to a XmlSchemaCollec tion object I get the
exception: System.InvalidC astException.

The most weird thing is that when I change the indicator to be
<xs:sequence> - it works fine (!)
And when I remove the object 'Child' it also works fine (!!!)
If I remove the 'additionalElem ent' it also works fine (!!!!!!)
What is wrong here? Could it be a bug?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 12 '05 #1
0 883

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

Similar topics

2
3600
by: Mike:o | last post by:
I need to validate XML documents (orders) against their schema before processing. The PurchaseOrder schema that we use references 3 other schemas using the <imports ...> element. Here is the relationship: - PurchaseOrder.xsd - Base.xsd - Item.xsd - Party.xsd These schemas are all located at a public Internet location. The imports elements within the PurchaseOrder schema look like this:
1
2695
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a "write to the database", we store the dataset's diffgram in the audit table. To render the audit report we load the diffgram into a generic DataSet and bind it to a grid. All works well unless the document's schema had an <xs:import> to bring...
1
2328
by: Dan Bass | last post by:
There's an XML message I have, that has no namespace information. Then there is a XSD schema that is must validate against, but this has a targetNamespace and xmlns of "http://www.wbf.org/xml/b2mml-v02". How do I get this XML to validate against the Schema in C#? If I use XmlSpy (2005 home edition) to perform the validation, it first inserts namespace and schema information into the XML before validating. Validation then seems to work if...
3
7424
by: Dave | last post by:
Hi, I'm really confused as to how to validate XML fragments against a schema in C#. I am creating XML through an automated process and have an .xsd which was given to me to validate against. Can someone give me some clue as to how to validate my XML string against this schema document? Is there some great secret that I'm missing?
2
4505
by: Ian | last post by:
I've inherited some xml that doesn't have a namespace and doesn't have a reference to the schema. The schema doesn't have a targetNamespace attribute. I'm trying to build a test tool, in C#, which will send the xml to the server and then validate the response against the schema. When I try and do this I get a "The attribute targetNamespace does not match the designated namespace URI" error. Here's a snippet of the validation code: ...
5
4958
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
5
2286
by: Sek | last post by:
Hi Folks, I would like to create a XML file that adhere to the Schema definition files. My schema definition files import/include further XSD files and internal references can be to a depth of two or three. The data required for the creation of XML are present in the form of user defined data structures.
3
4497
by: JMD | last post by:
A set of xsd files has been working fine for us at this site, but now it gives *intermittent* errors for someone at a different cite (who is consuming the code we are producing). Most of the time it works fine. Occasionally it gives an error in the schema compiler: "System.Xml.Schema.XmlSchemaException: Wildcard '##other' allows element 'Page', and causes the content model to become ambiguous. A content model must be formed such that...
3
3647
by: jh3an | last post by:
Please give me your advice! I made two files according to xml book, but when validating these two files, it gives me an error that I totally don't understand. Is there a problem in these codes? I checked xml and schema files through these following sites: http://tools.decisionsoft.com/schemaValidate/
0
9980
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, 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...
0
9826
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
11236
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
10468
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
9641
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...
0
7172
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
6061
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
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
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.