472,967 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,967 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 2131
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.