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 <root> at first line, and </root> at 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 ***
0
tomchang (2)
9/10/2008 5:19:51 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
672 Views

Similar Articles

[PageSpeed] 45

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/library/system.xml.xmlreadersettings.conformancelevel.aspx

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



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
9/10/2008 11:38:10 AM
Reply:

Similar Artilces:

Read HttpWebRespponse by XmlTextReader throws XmlException: Root element not present
I'm trying to read response from a web server using XmlTextReader. Here's a code snippet. WebResponse rs = this.WebRequest.GetResponse(); Stream stm = rs.GetResponseStream(); XmlTextReader reader = new XmlTextReader(stm); reader.XmlResolver = null; // no DTD/schema, high perf while (reader.Read()){ switch (reader.NodeType){ default: Debug.WriteLine(string.Concat( reader.NodeType.ToString(), ": ", "<", reader.Name, ">", reader.Value)); break; } } and data on the web is like this:...

I need the syntax for the cube root function in excel.
I am using a spreadsheet to automate a calculation requiring the cube root of a number. Thank you in advance, =125^(1/3) =POWER(125,1/3) -- Regards Ken....................... Microsoft MVP - Excel Sys Spec - Win XP Pro / XL 97/00/02/03 ---------------------------------------------------------------------------- It's easier to beg forgiveness than ask permission :-) ---------------------------------------------------------------------------- "Andy" <Andy@discussions.microsoft.com> wrote in message news:B6A15D37-2EB3-4F0B-A4FA-10A2E304E13B...

Public folder root permissions
I was recently changing permissions on the Root Public folder, the folder that allows other folders to be created. In changing the permissions I changed the everyone to deny all. I know, that was a really bad move. Right now I cannot access the permissions or even create a public folder. When I right click on the root public folder the option to create a public folder is grayed out. I assigned myself as Domain admin, and still no dice. Is there anyway of getting the those permissions changed? Hi, "SOX" <SOX@discussions.microsoft.com> schrieb im Newsbeitrag news:E9FA0...

Root element in XML designer and .xsd'd
Forgive a newbie question. I'm learning the .NET XML environment. In the walkthrough on using XML designer to create an xsd, there is no discussion of the root element of the target xml document. I realize that the namespace specifying the xsd is an attribute of the root element of an xml document conforming to the xsd, so is logically outside the xsd. I built a simple schema, then added an XML document, added a root element to the document, and specified an xmlns attribute to link in the schema. The correct schema is shown in the document property, and intellisense shows the eleme...

Deleted Root Web Exchange Server 2003
Didn't think I needed my root web so I deleted it. Low and behold this is what I used for OWA. How do I set up a new link to OWA? Thanks. Restore metabase from right before you did this - with Windows 2003 it backs it up often. Otherwise: Remove IIS and add it back. Run setup /disasterrecovery from the Exchange CD. -- Hope that helps, Dan Townsend This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email to this address, post a reply to this newsgroup. Use of included script samples are subject to the terms specified at http://w...

Could I get any code to get all files in root-directory (in FAT32)?
Hello.. Please help me. Please. I'm reading FAT32. A root-directory (in my HDD as FAT32) have 600 files. I tried to read the root-directory entry. But I failed to read all entries. (just 256..?) So I'm trying to get any code to get all entries any directory.(or root-directory) Please help me. Please.. "keandi" <keandi@lycos.co.kr> wrote in message news:56d0b84b-cc1c-45ed-95f3-519d7c21ac76@d27g2000prf.googlegroups.com... > Hello.. Please help me. Please. > > I'm reading FAT32. > A root-directory (in my HDD as FAT32) have 600 files. > I tried to r...

Determine Root Element
Using C# and the XmlDocument object I need to be able to determine the root element of an XML doc. I am processing docs that may either have the root element of <NewOrder> or <OrderUpdate>. How can I determine what it is? XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLBody); string sRoot = doc.??; //What do I do here? if(sRoot == "NewOrder") .... Dan wrote: > Using C# and the XmlDocument object I need to be able to determine the root > element of an XML doc. I am processing docs that may either have the root > element of <NewOrder> or <Orde...

move to... mailbox root folder lost message
If I right click a message from my inbox, and choose move to folder... and choose the root of the mailbox tree the one with the outlook today view and move the message there it appears to be gone forever. Can someone tell me how to get that message back? thanks oh, you right click and under home page tab uncheck show home page by default :/ scottevansh...@googlemail.com wrote: > If I right click a message from my inbox, and choose move to folder... > > and choose the root of the mailbox tree the one with the outlook today > view > > and move the message there it appea...

The root element is missing when binding dataset to xml textreader
Hi, I am attempting to create a xml file to a memory stream the bind it to a dataset. I can write a physical file with no problem. However I recieve the following error when trying to bind it to a dataset: Exception Details: System.Xml.XmlException: The root element is missing. Here is my code: MemoryStream ms = new MemoryStream(); XmlTextWriter xmlWriter = new XmlTextWriter(ms, Encoding.UTF8); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("menu"); xmlWriter.WriteStartElement("menuItem"); xmlWriter.WriteElementString("text", "NewArticles&...

Edit workflow rule fails with 'The root element is missing'
Editing rule as usual and I get the above error. New rule fails as well. I am simply trying to add a condition over a field that is a lookup field on the form and I have never had trouble before. Only thing I can think of is that the entity name in the CRM was changed from the original but that was many months ago. CRM 3.0 Any ideas? ...

locate square root symbol (not words)
I need to use the actual symbol for square root not the function SQRT in order to print formula's for a calculus class. I can't find it on the Symbols tables Insert>symbol and character code 221A -- Regards, Peo Sjoblom "Samir" <Samir@discussions.microsoft.com> wrote in message news:612BEA64-8CBC-46B2-AC73-4BFECF3AFC28@microsoft.com... >I need to use the actual symbol for square root not the function SQRT in > order to print formula's for a calculus class. I can't find it on the > Symbols > tables Or, use Insert | Object | Microsof...

Square Root
How does one calculate the Nth square root of X. Is there a function? Anyone has formula to acomplish this? Thanks for your help. Regards Sadik Hi Sadik try =POWER(value,1/n) or =value^(1/n) Frank Sadik wrote: > How does one calculate the Nth square root of X. Is there > a function? Anyone has formula to acomplish this? Thanks > for your help. > > Regards > Sadik Frank, Thanks a lot. Its so easy when you know it. Thanks. Regards Sadik >-----Original Message----- >Hi Sadik >try >=POWER(value,1/n) >or >=value^(1/n) > >Frank > >Sadik w...

Entreprise trusted root authorithy certificates
Hi, I try to understand how enterprise certificates works. With the certificates console, on my computer, in Certificates node of the Trusted Root Certification Authorities node, I have three identical certificates delivered by the same root authority. I don't understand why I have three identical certificates. Can somebody explain ? Thank you. Chris Hi, Are the certificates in your Trusted Root Certificate Authorities node all from your Enterprise CA? Typically when you create an Enterprise CA, it will publish its certificates to active directory. If you go to a comma...

ERR: The root element is missing
I'm in a real pickle. I've inherited a project with major problems. It receives encrypted XML files from a website not under my control (so I can't modify the web app) for insertion into a database. I'm under intense pressure to get the data into the database NOW. I can decrypt the files alright and they look like xml, they'll import into Access 2K3 with no problem, but VB.Net will not read them. It's complaining about no root element, and it's right there is no root element. I've tried manually adding a root to the decrypted file but the remainder ...

Cannot find root element in XML file
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which querying root returns null: [code] <?xml version="1.0" encoding="UTF-8"?> <IncidentDefinitions xmlns="http://tempuri.org/XML...

XML Schema problem : "Validate failed because the document does not contain exactly one root node"
Well, I'm with a strange problem here... I Have an Application in VC++ 6 and I need to load a XML file;This XML file has a XDS Schema validating it. I'm using MSXml4. Well, when I use the XML Spy with the two files, no problem , the XML file is validated. So I go to the VC and try to load, using the DOM to do it...ok, I can load and validate the file in both ways, with the put_validateOnParse(I'm using raw_interfaces_only) and with the validate() method. So, I Modify the XML file, taking off one simple letter, eg. changing the attribute name "Description" to "Desc...

Get Physical Path of Site Root Directory
Hi i wanted to know that given a site name that exists on my system using IIS, how can i get the physical path of its www directory using VC++. Also how to do so if i dont have the name of the site rather its index number e.g '12'..(I'm talking about the number that is appended with W3SVC folder name). Thanx and regards Usman Jamil ...

The Root BU
Can You Pleas Answer these Questions for Me. 1 The Root BU are Created from the Company Name that the licenses Key is Reg. to What is the importance of this Name (Will this Name Come On my invoice and statements?) or what 2 if you create an Opportunity or Lead can you log down the Fields on the Forms E.g Like the name should start with a Capital Letter You must enter an area Code with a Tel phone Nr before it can SAVE "CRM NEWB�e" <undead@iafrica.com> wrote in message news:eJDgLpCcFHA.1148@tk2msftngp13.phx.gbl... > > Can You Pleas Answer t...

console root folder
When opeing device manager, an empty console root folder opens first. How do I get rid of this empty folder msg wrote: > When opening device manager, an empty console root folder opens first. How do > I get rid of this empty folder? Maybe by repairing the registry entries for the Device Manager. http://www.kellys-korner-xp.com/xp_tweaks.htm 107. Restore the Device Manager More: http://www.kellys-korner-xp.com/xp_abc.htm Click "D" and scroll down to "Device Manager". -- Joe =o) ...

Mess in root DNS namespace
Hi, I'm having trouble after migrating a primary dns zone to active directory integrated. Before: private namespace is mycompany.local DC1 - W2K SP4 - DNS (primary) - DHCP - all FSMO roles DC2 - W2K SP4 - DNS (secondary) - DHCP (different scope from DC1) No errors in DNS eventlog. --> I upgraded mycompany.local zone to active directory integrated to get benefists of multimaster replication: everything went fine on DC1, so I had a fresh copy of text dns file transformed into system\MicrosoftDNS\mycompany.local branch of AD. --> I forced AD replication in AD Sites And Services t...

XmlArrayItem not allowed on Root Elements
I'm trying to serialize a collection, which is the root element, however the items in the collection contain derived classes, and thus give an error without XmlArrayItem attributes. However I can't add these to the field I'm copying from as its the root element, and so they appear to get ignored. Now the obvious answer is to put them in a wrapper and serialize the wrapper, which is okay, but I was wondering why this restriction is in place is can you get around it? Any Use ?? *********************************************************** <XmlRoot(ElementName:="WhatEverWontB...

Inconsistency between global catalog in root and global catalog in child domains
Hi, I have a very strange problem in my AD. It seems that there is an inconsistence between global catalog in the root domain and global catalog in the child domains. Global catalog on all root domain controllers are identical. Global catalog on all child domain controllers are identical. However (at least) one orphaned object exist in the global catalog on the child DC's, but not in global catalog on the root DC's. The object is not accessible through adsiedit, ldp, etc. and thus we cannot delete it. Does anybody have a good idea on how to get this object deleted. How the inco...

How to obtain the root of f(x) in this interval?
I am trying to draw a graph here, plotted graph x, with function f(x) at y-axis, does anyone know how to get the approximation to the root of f(x) in this interval. What is the value of x if i wish to obtain f(x)=0? In article <76A8C811-8C27-4E2B-AE6F-25BA4838B142@microsoft.com>, Gaenn@discussions.microsoft.com says... > I am trying to draw a graph here, plotted graph x, with function f(x) at > y-axis, does anyone know how to get the approximation to the root of f(x) in > this interval. What is the value of x if i wish to obtain f(x)=0? > If you know the function, use ...

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....

Deserialization with CollectionBase and attribute on root element
I've got a simple XML document (from an external source that I can't change) that I'm having trouble deserializing correctly. The document looks like: <?xml version='1.0'?> <quotes timestamp="17:49:23"> <quote id="0" value="foo"/> <quote id="1" value="bar"/> </quotes> I've defined a class "quotes" derived from CollectionBase and all of my deserialization is working fine except that I can't figurout how to deserialize the "timestamp" attribute on the root...