473,748 Members | 6,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Node Type = XmlNodeType.Ele ment Then
Console.WriteLi ne("Node:" & readWNInfo.Name & _
", AttributeCount: " & _
readWNInfo.Attr ibuteCount.ToSt ring())
End if
End while
readWNInfo.Clos e()

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 10992
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 XmlReaderSettin gs()
set.Conformance Level = ConformanceLeve l.Fragment
Using reader As XmlReader = XmlReader.Creat e("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
1624
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 this page I get: C:\inetpub\wwwroot\
1
2164
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 on multiple compilers (specificly, Visual C++ on windows and GCC 3.x MingW on windows. If it works on GCC on Linux, thats even better but not essential) What I am storing in this tree is data for a directory tree (its going to represent the...
2
2758
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 ElementID="1"></Element> <Element ElementID="2"></Element> <Element ElementID="3"></Element> </Elements>
5
7223
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 'D:\appfolder\test2'. ASPNET has full control on the application folder. Any ideas why this fails? - Tom
5
1825
by: TomislaW | last post by:
What is asp.net equivalent for Application("Root") in asp?
0
2030
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 problems. I will outline the problem, what I have tried to do to fix it, and what I think caused it. Hope you can help and I am sorry this is long. The problem: I can't login to mysql anymore with the "root" username (which is where I have all...
0
1222
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 objects, etc. At present, I'm using the following code to create a .xml file from the root element of those objects: FileStream fs = new FileStream(targetFileName, FileMode.CreateNew); try {
1
22842
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 suggestions from the Net, nothing seems to work. How do I correct the problem?
2
4708
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, FileMode.Create, FileAccess.Write)) { XmlWriter conWriter = new XmlTextWriter(conStream, Encoding.UTF8); conWriter.WriteStartDocument(); conWriter.WriteStartElement("myrootnode"); conWriter.WriteStartElement("myfirstnode"); conWriter.WriteEndDocument();
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.