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

help with reading xml file

Hello, I am working in .Net C# and have an xml file similar to the one
below. I have tried using a DataSet but get the error "The same table
(Gid) cannot be the child table in two nested relations". The file
has a number of parent nodes at the "<ShipmentHeader>" level, each of
which have a number of child nodes. I will not know ahead of time
which of these parent/child node relationships will occur. I have
looked at the XmlTextReader, but it looks like I would have to
evaluate NodeTypes, ReadInnerXml, etc. Is there an easier way?

<?xml version="1.0" encoding="UTF-8" ?>
<Shipment>
<ShipmentHeader>
<ShipmentGid>
<Gid>
<DomainName>xxxxx</DomainName>
<Xid>xxxxxxx</Xid>
</Gid>
</ShipmentGid>
<ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>xxxxx</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>xxxxx</ShipmentRefnumValue>
<ShipmentRefnum>xxxxx</ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>xxxx</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>xxxxxx</ShipmentRefnumValue>
</ShipmentRefnum>
</ShipmentHeader>
</Shipment>
Nov 16 '05 #1
1 1227
Hi!

You have too many levels in your XML file. To create an xml file that .NET
can read (without a schema), you should use the following structure.

<?xml ... ?>
<datasetname>
<tablename>
<columnname>columndata</columnname>
<columnname>columndata</columnname>
</tablename>
<tablename>
<columnname>columndata</columnname>
<columnname>columndata</columnname>
</tablename>
</datasetname>

So the document element becomes your DataSet. Below it, there are elements.
These will be sorted into tables. If these element names are the same, they
are added to the same table. Else, they are added to different tables.
Columnnames then are simply names of the columns, and they contain the data
you want in that column.

This is the case without a schema. With a schema, you could make it work
with other kinds of datasets, but by default, my experience is, it reads and
writes in this format.

-Artur

PS: some example

<customersdb>
<customer>
<name>Peter</name>
</customer>
<customer>
<name>Jane</name>
</customer>
<order>
<by>Peter</by>
<what>book</what>
</order>
<customersdb>

This would create a dataset named customersdb with two tables, named
customer and order. The customer table would have two rows. The order table
would have one row.

"davis" <my**********@yahoo.com> wrote in message
news:a8**************************@posting.google.c om...
Hello, I am working in .Net C# and have an xml file similar to the one
below. I have tried using a DataSet but get the error "The same table
(Gid) cannot be the child table in two nested relations". The file
has a number of parent nodes at the "<ShipmentHeader>" level, each of
which have a number of child nodes. I will not know ahead of time
which of these parent/child node relationships will occur. I have
looked at the XmlTextReader, but it looks like I would have to
evaluate NodeTypes, ReadInnerXml, etc. Is there an easier way?

<?xml version="1.0" encoding="UTF-8" ?>
<Shipment>
<ShipmentHeader>
<ShipmentGid>
<Gid>
<DomainName>xxxxx</DomainName>
<Xid>xxxxxxx</Xid>
</Gid>
</ShipmentGid>
<ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>xxxxx</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>xxxxx</ShipmentRefnumValue>
<ShipmentRefnum>xxxxx</ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>xxxx</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>xxxxxx</ShipmentRefnumValue>
</ShipmentRefnum>
</ShipmentHeader>
</Shipment>

Nov 16 '05 #2

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

Similar topics

2
by: nephish | last post by:
Hey there, i am trying to write an online application using the cgi module. what i want to do is have an html form display a drop-down list and have the values of that list be the lines of text...
1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
2
by: Parker.Jim | last post by:
I need to write a program which performs word subsitutions on a text file. The program should input the names of three text files: the source file that will be "edited", a text file that contains...
3
by: Chi | last post by:
what is the "unable to write data to the transport connection" I use the oreilly , programming c# using System; using System.Net.Sockets; using System.Text; using System.IO; // get a file...
36
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
2
by: -D- | last post by:
I'm taking my first stab at using xml, so please bear with my novice questions and understanding of xml. I'm trying to create an xml file that holds all my website navigation. If I understand...
1
by: syhzaidi | last post by:
How can we do Parsing of Hexdecimel in C# reading string from stream file for eg.. i have a file like.......... 0f 2f 12 2d 3a.......in hexa decimal save in a file.txt and i m reading it from...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.