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

Multiple parent nodes

I'm creating an xml file from some data and I'm geting repeating parent
nodes in the xml file. Not sure where I'm going wrong?

<?xml version="1.0" standalone="yes"?>
<MyTestData xmlns="http://www.mytestdata.com/list_data.xsd">
<Wigets>
<Wiget>Muffler Bearing</Wiget>
</Wigets>
<Wigets>
<Wiget>5 gallons of prop wash</Wiget>
</Wigets>
<Wigets>
<Wiget>gonkalator armature</Wiget>
</Wigets>
<Gizmos>
<Gizmo>hole-mover</Gizmo>
</Gizmos>
<Gizmos>
<Gizmo>bulkhead remover</Gizmo>
</Gizmos>
</MyTestData>


ArrayList alWigets = new ArrayList();
ArrayList alGizmos = new ArrayList();
alWigets.Add("Muffler Bearing");
alWigets.Add("5 gallons of prop wash");
alWigets.Add("gonkalator armature");
alGizmos.Add("hole-mover");
alGizmos.Add("bulkhead remover");

DataSet ds = new DataSet("MyTestData");
ds.Namespace = "http://www.mytestdata.com/list_data.xsd";

DataTable dtWigets = new DataTable("Wigets");
DataTable dtGizmos = new DataTable("Gizmos");
dtWigets.Columns.Add("Wiget");
dtGizmos.Columns.Add("Gizmo");

string[] myWiget = new string[1];
string[] myGizmo = new string[1];

for (int i = 0;i < alWigets.Count; i++)
{
myWiget[0] = alWigets[i].ToString();
dtWigets.Rows.Add(myWiget);
}
for (int i = 0;i < alGizmos.Count; i++)
{
myGizmo[0] = alGizmos[i].ToString();
dtGizmos.Rows.Add(myGizmo);
}

ds.Tables.Add(dtWigets);
ds.Tables.Add(dtGizmos);

ds.WriteXml("stuff.xml");

Feb 6 '06 #1
3 1599
Hi Tom,

Your XML file seems kinda strange to me. You need to define a proper
structure. I would like to see the XSD you're using, thought. You might
use this format in your stuff.xml file: (And by the way, it's spelled
"Widget" ;-))

<?xml version="1.0" standalone="yes" ?>
<MyTestData xmlns="http://www.mytestdata.com/list_data.xsd">
<AllWidgets>
<Widget>Muffler Bearing</Widget>
<Widget>5 gallons of prop wash</Widget>
<Widget>gonkalator armature</Widget>
</AllWidgets>
<AllGizmos>
<Gizmo>hole-mover</Gizmo>
<Gizmo>bulkhead remover</Gizmo>
</AllGizmos>
</MyTestData>

See if this helps. ;-)

Feb 7 '06 #2
Thanks for your reply, The strange xml is my problem...why does
ds.WriteXml produce this strange xml structure?

Feb 7 '06 #3
Hi Tom,

The problem as I see it is that your Dataset is an Untyped dataset.
This means that it doesn't have an associated schema.
Setting
ds.Namespace = "http://www.mytestdata.com/list_data.xsd";
will not help in this regard.

You need to create an appropriate schema that defines the structure of
the XML you want to create. Then read the schema into the dataset. This
will create a Typed Dataset. An example :
------------------------------------------
DataSet ds = new DataSet("MyTestData");
string filename=@"..\..\list_data.xsd"; // The location relative to
the Bin\Debug folder.
XmlTextReader xtr = new XmlTextReader(filename);
// Read the schema into the DataSet and close the reader.
ds.ReadXmlSchema(xtr);
xtr.Close();

ds.Namespace = "http://www.mytestdata.com/list_data.xsd";

:
:
// Proceed with filling the datatables.
:
:
ds.WriteXml("stuff.xml");
------------------------------------------
This works to produce the format of XML that I suggested. So, to
reiterate, the key here is to determine the exact format of XML you
want, then create a schema for that. Then read that schema into the
Dataset, *before* you start filling in data into the Dataset.

Hope this helps,

Regards,
Cerebrus99.

Feb 8 '06 #4

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

Similar topics

3
by: Hazz | last post by:
I am just beginning to design a Treeview display (winforms) for wine regions. Problem. Some wine growing regions belong to two counties. Eg. Carneros is in both Napa and Sonoma Counties. Although...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
4
by: jarek | last post by:
Hi, this is my code: CSSStyleDeclaration.prototype.__defineSetter__('display', displaySetter); function displaySetter(value) { var parent = findParent(document, this); if (parent) {
0
by: Nihar | last post by:
Hello all, I m just trying to add multiple nodes to an existing xml file. Here is my sample. <ADT> <IN1> <DG1> <GT1>
0
by: Mel | last post by:
I have a treeview control that contains a list of filenames which I am searching. If a file in the tree matches the search criteria the entire node is expanded. Often times there are other files...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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,...
0
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...

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.