473,385 Members | 1,630 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.

How to read XML file without "Root" Node

Try to read following type of XML file, but only get data back on first
node:

<log id="1234">
<message type="Action"/>
</log>
<log id="5678">
<message type="Drama"/>
</log>
<log id="1357">
<message type="Art"/>
</log>

Here is my very simple VB program:

Imports System.IO
Imports System.Xml
Dim readWNInfo As XmlTextReader
readWNInfo = New XmlTextReader("test.log")
While readWNInfo.Read()
If readWNInfo.NodeType = XmlNodeType.Element Then
Console.WriteLine("Node:" & readWNInfo.Name & _
", AttributeCount: " & _
readWNInfo.AttributeCount.ToString())
End if
End while
readWNInfo.Close()

If I add <rootat first line, and </rootat the end, the above code
works. Can I make work without modify the original log file?

Thanks for your help in advance,

Tom

*** Sent via Developersdex http://www.developersdex.com ***
Sep 10 '08 #1
2 10944
Tom Chang wrote:
Try to read following type of XML file, but only get data back on first
node:

<log id="1234">
<message type="Action"/>
</log>
<log id="5678">
<message type="Drama"/>
</log>
<log id="1357">
<message type="Art"/>
</log>
If you have .NET 2.0 or later then use
Dim set as New XmlReaderSettings()
set.ConformanceLevel = ConformanceLevel.Fragment
Using reader As XmlReader = XmlReader.Create("test.log", set)
While reader.Read()
'read out properties here
End While
End Using

See
http://msdn.microsoft.com/en-us/libr...ancelevel.aspx

That way you can process fragments of XML that don't have a root element.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 10 '08 #2
Martin,
Thanks for your help. It works!
- Rgds, Tom

*** Sent via Developersdex http://www.developersdex.com ***
Sep 10 '08 #3

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

Similar topics

2
by: Larry Woods | last post by:
I have defined a virtual directory and application called Test. The directory is C:\inetpub\wwwroot\Test. I created a trivial page: <% response.write Server.Mappath("/") %> When I execute...
1
by: Jonathan Wilson | last post by:
I am looking for a C++ class library that can store data in a tree. The class library needs to be: 1.Available under a licence like GPL, LGPL or BSD so I can use it in my GPL program and 2.Usable...
2
by: John A Grandy | last post by:
Is there something special in XML about the name "Parameter" ... I am not able to XPATH query for nodes named "Parameter" <Root> <Category CategoryID="1"> <Elements> <Element...
5
by: Tom Vogel | last post by:
Creating a subfolder within my ASP.NET application folder fails with the above error, but only at my hosting provider. The command: Directory.CreateDirectory(path) Path is set to...
5
by: TomislaW | last post by:
What is asp.net equivalent for Application("Root") in asp?
0
by: damontimm | last post by:
My setup: Mac OS 10.4.4; mysql 4.x ... everything was installed and working fine for some time. Today, I added drupal to my system and had to create a new database in mysql -- now I am having some...
0
by: soccerdad | last post by:
I'm trying to make sure that I'm using the correct .NET 2.0 mechanism to serialize objects to XML files. I've used XSD.EXE to generate classes from a 3rd party .xsd file. I can populate those...
1
by: edwige | last post by:
I just installed PostgreSQL on ubuntu linux. the installer does everything for, but I try to use "createuser" I get this message: { FATAL: role "root" does not exist } I have tried different...
2
by: danimian | last post by:
Hello, first i am creating xml file if file does not exist. String myFile = "C:\myxmlfile.xml"; if (!File.Exists(myFile)) { using (FileStream conStream = new FileStream(myFile,...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.