Re: help with reading xml file

From: Artur Sorszegi (artursorszegi_at_freemail.hu)
Date: 07/29/04


Date: Thu, 29 Jul 2004 14:41:04 +0300

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" <mycsharpmail@yahoo.com> wrote in message
news:a8887c5d.0407290321.244b3e8a@posting.google.com...
> 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>



Relevant Pages

  • Re: User-defined attributes in XMLSchema
    ... While validating an xml file against the schema in .NET 2.0, ... shown below in the code sample: ...
    (microsoft.public.dotnet.xml)
  • Re: User-defined attributes in XMLSchema
    ... know if they succeded to find the attribute in the schema as described below. ... While validating an xml file against the schema in .NET 2.0, ... shown below in the code sample: ...
    (microsoft.public.dotnet.xml)
  • Re: User-defined attributes in XMLSchema
    ... ..NET XmlSchema Object Model, the search:able attribute will be stored in the ... While validating an xml file against the schema in .NET 2.0, ...
    (microsoft.public.dotnet.xml)
  • Re: "Filter" data from XML datafile into datagrid
    ... Just paste the XML file from Thomas on an empty item XML file that you have ... Than just right click and say create schema. ... dataset with posible relations between the customer and the projectinfo. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)