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

Reading XML file... getting tables but no rows...

(FYI, using VB .NET 2003)
Can someone help me with this... I'm trying to read in an XML file... it
appears to work in that the DataSet ReadXML method dose not fail and then I
am able to access the table names that are in the XML file, but I'm not able
to access the rows.
Here's the code that I've got - it assumes that the fileName passed in
already exists:

Public Sub GetInput(ByVal fileName As String)
dsFileCopy = New DataSet("fileCopy")
Dim dtActions As DataTable = New DataTable("action")
Dim dtIni As DataTable = New DataTable("ini")
dtIni.Columns.Add("title", Type.GetType("System.String"))
dtIni.Columns.Add("information", Type.GetType("System.Boolean"))
dtActions.Columns.Add("source", Type.GetType("System.String"))
dtActions.Columns.Add("target", Type.GetType("System.Boolean"))
dtActions.Columns.Add("type", Type.GetType("System.Boolean"))
dsFileCopy.Tables.Add(dtIni)
dsFileCopy.Tables.Add(dtActions)
Try
dsFileCopy.ReadXml(fileName)
Catch ex As Exception
'if the file is blank or not in XML format we will fall here
Trace.WriteLine("Invalid status file " & fileName)
MsgBox(ex.ToString, MsgBoxStyle.Exclamation, "NSDUH FileCopy")
Application.Exit()
End Try
End Sub

The above code works fine, but I get a run-time error when I execute the
following statement:
Debug.WriteLine(dtIni.Rows(0).Item("information"))
The error says there is no row(0) in the table... So maybe I'm accessing the
elements of the table wrong. What I want todo is loop through each row and
perform each action based on the specifications... Am I accessing the DataSet
element correctly?

So, I tried printing all the elements in the DataSet using this code:
Private Sub PrintDataSet(ByVal dsActions As DataSet)
For Each t As DataTable In dsActions.Tables
Console.WriteLine("TableName: " + t.TableName)
For Each r As DataRow In t.Rows
For Each c As DataColumn In t.Columns
Console.Write(ControlChars.Tab + " " + r(c).ToString())
Next c
Console.WriteLine()
Next r
Next t
End Sub
But all that prints to the console is the names of the tables...
Here's the XML file:
<?xml version="1.0" standalone="yes" ?>
<fileCopy xmlns="http://tempuri.org/FileCopyInput.xsd">
<ini>
<title>Some Title here</title>
<information>Other info here</information>
</ini>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>copy</type>
</action>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>move</type>
</action>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>delete</type>
</action>
</fileCopy>

Any input would be greatly appreciated.

Charles
Jan 13 '06 #1
1 2156
I don't know the details but it looks like the contents of the xml file I was
reading in was causing the problem... maybe someone out there can provide a
through explination as to what the situation is.

Here's how my "FileCopyInput.xml" originally began:
<?xml version="1.0" standalone="yes" ?>
<fileCopy xmlns="http://tempuri.org/FileCopyInput.xsd">
:
:

When I removed (commented out) the "xmlns" attribute from the FileCopy node,
everthing worked just fine. So here's how the file looks now:

<?xml version="1.0" standalone="yes" ?>
<!--<fileCopy xmlns="http://tempuri.org/FileCopyInput.xsd">-->
<fileCopy>

Obviously I played around with defining my own xml schema and it got inseted
into the XML file I was defining. How would I change the xmlns attribute to
point to the XML schema that I defined? can I use a file:/// URL? Or specify
local host?
I'd appreciate any feedback and/or links for reading!

THanks,
Charles

"hz****@nopost.com" wrote:
(FYI, using VB .NET 2003)
Can someone help me with this... I'm trying to read in an XML file... it
appears to work in that the DataSet ReadXML method dose not fail and then I
am able to access the table names that are in the XML file, but I'm not able
to access the rows.
Here's the code that I've got - it assumes that the fileName passed in
already exists:

Public Sub GetInput(ByVal fileName As String)
dsFileCopy = New DataSet("fileCopy")
Dim dtActions As DataTable = New DataTable("action")
Dim dtIni As DataTable = New DataTable("ini")
dtIni.Columns.Add("title", Type.GetType("System.String"))
dtIni.Columns.Add("information", Type.GetType("System.Boolean"))
dtActions.Columns.Add("source", Type.GetType("System.String"))
dtActions.Columns.Add("target", Type.GetType("System.Boolean"))
dtActions.Columns.Add("type", Type.GetType("System.Boolean"))
dsFileCopy.Tables.Add(dtIni)
dsFileCopy.Tables.Add(dtActions)
Try
dsFileCopy.ReadXml(fileName)
Catch ex As Exception
'if the file is blank or not in XML format we will fall here
Trace.WriteLine("Invalid status file " & fileName)
MsgBox(ex.ToString, MsgBoxStyle.Exclamation, "NSDUH FileCopy")
Application.Exit()
End Try
End Sub

The above code works fine, but I get a run-time error when I execute the
following statement:
Debug.WriteLine(dtIni.Rows(0).Item("information"))
The error says there is no row(0) in the table... So maybe I'm accessing the
elements of the table wrong. What I want todo is loop through each row and
perform each action based on the specifications... Am I accessing the DataSet
element correctly?

So, I tried printing all the elements in the DataSet using this code:
Private Sub PrintDataSet(ByVal dsActions As DataSet)
For Each t As DataTable In dsActions.Tables
Console.WriteLine("TableName: " + t.TableName)
For Each r As DataRow In t.Rows
For Each c As DataColumn In t.Columns
Console.Write(ControlChars.Tab + " " + r(c).ToString())
Next c
Console.WriteLine()
Next r
Next t
End Sub
But all that prints to the console is the names of the tables...
Here's the XML file:
<?xml version="1.0" standalone="yes" ?>
<fileCopy xmlns="http://tempuri.org/FileCopyInput.xsd">
<ini>
<title>Some Title here</title>
<information>Other info here</information>
</ini>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>copy</type>
</action>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>move</type>
</action>
<action>
<source>.\fileA</source>
<target>C:\destinationA</target>
<type>delete</type>
</action>
</fileCopy>

Any input would be greatly appreciated.

Charles

Jan 16 '06 #2

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

Similar topics

2
by: Bob | last post by:
Everybody, I've been doing a lot of on-line research and cannot find any reference to the exact problem I'm having. Let me preface this question with the fact that I'm coming from an Oracle...
4
by: Deepa | last post by:
Hi I have a DataSet file (xml) which I need to convert it into a tab delimited file. I need to write a C# console application for doing the same. Can anyone help me out with the code to do it? I'd...
3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
6
by: ALI-R | last post by:
Hi All; I'm reading the following xml file into a Dataset but there are only 4 datatables in my dataset (which should be 5) Is that because I have two nodes with the same name (detail) in my xml...
1
by: Mr. B | last post by:
VB.net 2003 c/w Framework 1.1 and MS Access db We have a commercial program that does our Acounting and Time Sheets (Timberline). At least once a day our Accounting department runs a Script...
0
by: c.w.browne | last post by:
Hi, Ive had a bit of a look around for other people with this problem and cant find anything that solves it in my case, so I'm afraid im going to have to bother you all with a post of my own. ...
2
by: rwiegel | last post by:
I'm trying to read rows from an Excel file and display them in an ASP.NET DataGridview. I am using C# for the code file. I am using OleDb to read from the Excel file. The columns that contain...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.