473,699 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Muffle r Bearing</Wiget>
</Wigets>
<Wigets>
<Wiget>5 gallons of prop wash</Wiget>
</Wigets>
<Wigets>
<Wiget>gonkalat or armature</Wiget>
</Wigets>
<Gizmos>
<Gizmo>hole-mover</Gizmo>
</Gizmos>
<Gizmos>
<Gizmo>bulkhe ad remover</Gizmo>
</Gizmos>
</MyTestData>


ArrayList alWigets = new ArrayList();
ArrayList alGizmos = new ArrayList();
alWigets.Add("M uffler Bearing");
alWigets.Add("5 gallons of prop wash");
alWigets.Add("g onkalator armature");
alGizmos.Add("h ole-mover");
alGizmos.Add("b ulkhead remover");

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

DataTable dtWigets = new DataTable("Wige ts");
DataTable dtGizmos = new DataTable("Gizm os");
dtWigets.Column s.Add("Wiget");
dtGizmos.Column s.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.A dd(myWiget);
}
for (int i = 0;i < alGizmos.Count; i++)
{
myGizmo[0] = alGizmos[i].ToString();
dtGizmos.Rows.A dd(myGizmo);
}

ds.Tables.Add(d tWigets);
ds.Tables.Add(d tGizmos);

ds.WriteXml("st uff.xml");

Feb 6 '06 #1
3 1609
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>Muffl er Bearing</Widget>
<Widget>5 gallons of prop wash</Widget>
<Widget>gonkala tor armature</Widget>
</AllWidgets>
<AllGizmos>
<Gizmo>hole-mover</Gizmo>
<Gizmo>bulkhe ad 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("MyTest Data");
string filename=@"..\. .\list_data.xsd "; // The location relative to
the Bin\Debug folder.
XmlTextReader xtr = new XmlTextReader(f ilename);
// Read the schema into the DataSet and close the reader.
ds.ReadXmlSchem a(xtr);
xtr.Close();

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

:
:
// Proceed with filling the datatables.
:
:
ds.WriteXml("st uff.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
2566
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 most nodes will have only one parent, a few will have two parents. The Treeview which seems to me to lend itself to the Windows Explorer type of app could not possibly show one file as a leaf belonging to two different parent folders. You either...
7
3766
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
2230
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
1630
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
2183
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 in that expanded node that don't match the criteria. Is there a way to highlight ALL the nodes that matched the search criteria? Example Code (Using ASP.NET 2.0, Visual Basic): Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As...
0
8700
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
8623
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
9184
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...
1
8931
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,...
0
8892
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
7767
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
5878
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
4386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2359
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.