473,839 Members | 1,396 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 1716

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

Similar topics

2
1786
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
10392
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
2132
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
4947
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
1372
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
8525
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
3406
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
1669
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
4966
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
9697
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
10908
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
10649
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
10295
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...
1
7829
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
7018
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
5682
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...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3136
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.