474,045 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with XmlNode - node.HasChildNo des always returns true even when no child exists

RJN
Hi

I have to read an xml and add the node elements into a hashtable with
nodename as key and nodetext as value. If the selected node has
childnodes, then value should go as an array.

for eg.,

<Root>
<mysection>
<logroot>e:\tem p</logroot>
<outputdir>
<dir1>e:\temp 1</dir1><dir2>e:\t emp2</dir2>
</outputdir>
</mysection>
<myanothersecti on></myanothersectio n>
</Root>

I would first search for "Root/mysection". Now since logroot doesn't
have further childnodes, I would like to add to the hashtable "logroot"
as key and "e:\temp" as value. The next node outputdir has 2 child nodes
dir1 and dir2. I would like to create a string array for the values of
dir1 and dir2 and add to the hashtable "outputdir" as key and the array
as value.

The following code is not working for me.

Dim strXml As String =
"<Root><mysecti on><logroot>e:\ temp</logroot><output dir><dir1>e:\te mp1</d
ir1><dir2>e:\te mp2</dir2></outputdir></mysection><myan othersection></mya
nothersection></Root>"
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml( strXml)
Dim xmlSection As XmlNode =
xmlDoc.SelectSi ngleNode("Root/mysection")
Dim htValues As New Hashtable
For Each node As XmlNode In xmlSection.Chil dNodes
If (node.HasChildN odes) Then
Dim str() As String
ReDim str(node.ChildN odes.Count - 1)
For i As Integer = 0 To node.ChildNodes .Count - 1
str(i) = node.ChildNodes (i).InnerText
Next
htValues.Add(no de.Name, str)
Else
htValues.Add(no de.Name, node.InnerText)
End If
Next

I always get node.HasChildNo des as true even though the node doesn't
have further child nodes. Because of this, I end up adding an array as
value for every node. If the values inside the node is empty then it is
working fine.

Any help is appreciated.

Regards

rjn

*** Sent via Developersdex http://www.developersdex.com ***
Apr 6 '06 #1
0 1741

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

Similar topics

2
1794
by: Arthur Dzhelali | last post by:
I have a two xml files schema is identical. When I read file into dataset and then bind dataset to the form. These are weather files we are getting from weather service. One file has only local weather so I don't have any problems with that, but other has weather for several different locations. Basically I need to select only weather for location if I know its code. I should have exactly same dataset so I will be able bind it to the...
2
10403
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation.
1
2148
by: Venkat Venkataramanan | last post by:
Hello: Can somebody explain to me the usage of the XMLNode.ChildNodes? When there is a node that does not have any child node, the above method returns an array of 1. This member has the following values: Name "#text"
1
4961
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
4
1377
by: Mark Cooney | last post by:
OK this might be long winded by want to show you everything I am doing. Down below is the result I get from an API Call to a website called Betfair. The following is some code I am trying, but I have also tried many different variations. Dim response As HttpWebResponse = request.GetResponse() 'Get the response stream Dim reader As StreamReader = New StreamReader(response.GetResponseStream)
5
8548
by: Christof Nordiek | last post by:
When I load a XML-Document from a file, and then get an XmlNode from it, is there any way to get the its original position in the file (line, character)? I want to report it, when there is something odd about that node, so that a user can find the position in the file. Similar to the errormessage from XmlDocument.Load, if the file isn't wellformed XML. If that's not possible, would it be possible when examining the XML with other...
1
3418
by: =?Utf-8?B?QmFydCBTdGV1cg==?= | last post by:
I have the following issue. I'm trying to read to following XML doc. <Main> <Submain> <SubField1/> <SubField2/> </Submain> <Field1/> <Field2>AnyTextValue</Field2> </Main>
14
1685
by: anju458 | last post by:
Hi, I had a function to compare two XML files within a project . Now I need to change that into a commandline exe in such a way that it whouls accept two params from the Command line. I have changed it .. but I am getting some errorr ValidatorUpg.ValidatorUpg.CompareXMLFiles(string, string, System.Xml.XmlDocument, System.Xml.XmlDocument)' cannot be accessed with an instance reference; qualify it with a type name instead ...
5
4983
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
10339
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
11604
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12027
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
11143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10313
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
8700
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
7872
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();...
2
4944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3973
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.