473,396 Members | 2,070 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,396 software developers and data experts.

Invalid XML document generated from WriteXML() on a strongly typed dataset

Hi all,

I've seen that many people have had this exact same problem in the past, but
no-one seems to post the answer when (if) they solve it... so here we go
again.

If I create a strongly typed dataset from an xsd schema I've created in
VS.NET 2002, instantiate and populate the dataset and write it as XML using
WriteXML() the generated XML file is not valid based on the xsd file used to
create the dataset.

When validating, the error is "The 'http://tempuri.org/Test.xsd:Test'
element is not declared. An error occurred at "... test_data.xml(2, 2)."

Here is the original xsd:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="NameType">
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="People" type="NameType"></xs:element>
</xs:schema>

Here is the code used to create and populate the dataset:

new Test().WriteXmlSchema("..\\..\\test_schema.xml");
t.People.AddPeopleRow("Joe", "Bloggs");
t.People.AddPeopleRow("Jane", "Doe");
t.WriteXml("..\\..\\test_data.xml");

And here is the generated output:

<?xml version="1.0" standalone="yes"?>
<Test>
<People>
<FirstName>Joe</FirstName>
<LastName>Bloggs</LastName>
</People>
<People>
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
</People>
</Test>

As you can see, the generated output has an additional root element - the
"Test" element.

I would have expected something like:

<?xml version="1.0" standalone="yes"?>
<People>
<FirstName>Joe</FirstName>
<LastName>Bloggs</LastName>
</People>
<People>
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
</People>
I know a lot of people have seen this before, but if someone could point me
in the right direction it'd be great! (I'll also post the answer for those
who follow!). I've obviously missed something fairly straightforward here!

I should also say I've tried using the the XMLDataDocument() clases, but I
cannot get the schema to stay the way I had expected - it works well loading
an XML file, manipulating it via the dataset and storing it again, but when
you don;t Load() an xml file, as in my case, it doesn't seem to work (even
if I try ReadXMLSchema() on the documents dataset prior to populating).

This is driving me crazy!

Thanks,
Dave.


Nov 12 '05 #1
1 3567
Hi all,

The answer to this question lies in how the xsd elements are coverted into
tables in the dataset.

The "rules" are explained in
http://msdn.microsoft.com/library/de...nceprocess.asp

Essentially what I found was I needed to add a root element at the top of
the schema with a single element as its child. This enabled the single
element (the old root node) to be turned into a table in the dataset, and
the root element in the schema to be transferred into the dataset name, and
hence back as the root element in the dataset generated xml file.

Hope this helps anyone else who comes across this issue.

Regards,
Dave.
Nov 12 '05 #2

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

Similar topics

4
by: Robert Scarborough | last post by:
I have a Table in a Typed Dataset which contains a Date field called EventDate. I've ensured that the field is defined as Date as opposed to DateTime in the Typed Dataset. When I generate an...
0
by: MT | last post by:
I have a very strange problem. I created an XSD file with the following root: <Database> </Database> However, since C++ does not allow you to have a property with the same name as the class,...
0
by: Anon | last post by:
I have an XML document that stores configuration settings for an app. I generated the schema using vs.net and also the corresponding dataset. I can load the config file (config.xml - below) and get...
0
by: Bill | last post by:
I have a strong typed dataset which I load using the following code. try { XmlTextReader xmlTR = new XmlTextReader("XIF-v1.0.xsd"); dsMyDataSet.ReadXmlSchema(xmlTR); if (p_FileName !=...
2
by: David | last post by:
I have been developing applications with Java for quite a while but I am new to .NET development. I am trying to learn the ".NET way" of creating Strongly Typed Objects from a database. The...
1
by: HardBap | last post by:
I've created a strongly typed DataSet (Customers.xsd) using the xsd.exe tool. I want to be able to access fields using ds.Customer.CompanyName. The problem is when I return this DataSet from a...
1
by: Lerp | last post by:
Hi all, I have a question regarding the best way to build a dynamic XML document from data stored in my database. From what I have read so far, I could build a dataset and then use this...
4
by: Bernie Yaeger | last post by:
I use the following writexml method to convert a dataset/datatable to .xml: ds.WriteXml(mstrpath, XmlWriteMode.WriteSchema) ds.WriteXmlSchema(mstrpathxsd) The path strings are simple full...
3
by: Tolga Erdogus | last post by:
Hi, for a project that I am wrapping up I am writing documentation. I'd like to be able to put in xmldoc style comments in to the source of my strongly typed dataset, its tables, relationshipts...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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,...
0
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...
0
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...
0
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...

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.