473,406 Members | 2,847 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,406 software developers and data experts.

XML Reading with XmlDocument

Hi,
I am having trouble with this code can't seem to load these email values any
Ideas?
XML File

<?xml version="1.0" ?>
<Sections>
<FilePath>
<Path>c:\temp\</Path>
</FilePath>

<Comment>Email list for Report</Comment>

<EMails>
<Address1>So*********@email.com</Address1>
<Address2>So**********@email.com</Address2>
<Address3>So**********@email.com</Address3>
</EMails>
</Sections>

VB Code:

Try

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

Dim intCounter As Int32

Dim strEmailText As String

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(m_strXMLPath)

'Get the list of Email nodes

m_nodelist = m_xmld.SelectNodes("/Sections/EMails")

'Loop through the nodes

For Each m_node In m_nodelist

'* Can't seem to load this as only the first get loaded??

strEmailText = m_node.ChildNodes.Item(intCounter).InnerText()

intCounter += 1

Next

Catch errorVariable As Exception

'Error trapping

End Try

Thanks


Nov 12 '05 #1
5 5708
Hi David,

I think the problem has to do with how you are using m_node in your loop.
Try changing your assignment statement to read:
For Each m_node In m_nodelist

'* Can't seem to load this as only the first get loaded??

strEmailText = m_node.ChildNodes.Item(intCounter).InnerText() Try this instead----> strEmailText = m_node.InnerText ' (Your m_node
variable references the current xmlnode in your nodelist

Hope this helps.

LarryR

"David Costelloe" <da************@sympatico.ca> wrote in message
news:ym*****************@news20.bellglobal.com... Hi,
I am having trouble with this code can't seem to load these email values any Ideas?
XML File

<?xml version="1.0" ?>
<Sections>
<FilePath>
<Path>c:\temp\</Path>
</FilePath>

<Comment>Email list for Report</Comment>

<EMails>
<Address1>So*********@email.com</Address1>
<Address2>So**********@email.com</Address2>
<Address3>So**********@email.com</Address3>
</EMails>
</Sections>

VB Code:

Try

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

Dim intCounter As Int32

Dim strEmailText As String

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(m_strXMLPath)

'Get the list of Email nodes

m_nodelist = m_xmld.SelectNodes("/Sections/EMails")

'Loop through the nodes

For Each m_node In m_nodelist

'* Can't seem to load this as only the first get loaded??

strEmailText = m_node.ChildNodes.Item(intCounter).InnerText()

intCounter += 1

Next

Catch errorVariable As Exception

'Error trapping

End Try

Thanks

Nov 12 '05 #2
Hi Larry,
Thanks for your reply
strEmailText = m_node.InnerText brings back everything (all 3 emails) in
one string with no spaces.
I am hoping to be able to load each email from the for each loop.

Thanks
David.......

"LarryR" <me@somewhere.com> wrote in message
news:OIHOb.6316$dd6.6239@lakeread02...
Hi David,

I think the problem has to do with how you are using m_node in your loop.
Try changing your assignment statement to read:
For Each m_node In m_nodelist

'* Can't seem to load this as only the first get loaded??

strEmailText = m_node.ChildNodes.Item(intCounter).InnerText() Try this instead----> strEmailText = m_node.InnerText ' (Your

m_node variable references the current xmlnode in your nodelist

Hope this helps.

LarryR

Nov 12 '05 #3
David Costelloe wrote:
Hi Larry,
Thanks for your reply
strEmailText = m_node.InnerText brings back everything (all 3 emails) in
one string with no spaces.
I am hoping to be able to load each email from the for each loop.


Then iterate over /Sections/EMails/* elements:

m_nodelist = m_xmld.SelectNodes("/Sections/EMails/*")

and get InnerText of each one.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #4
Hi,

I tried this:
Dim strEmailText as string
m_nodelist = m_xmld.SelectNodes("/Sections/EMails/*")

'Loop through the nodes

For Each m_node In m_nodelist

strEmailText = m_node.ChildNodes.Item(intCounter).InnerText()

intCounter += 1

Next

I must be missing something as everything I tried has brought back the 3
emails as one string?

This has got me baffled I even tried this in the loop

strEmailText = m_node.Item("Address" & intCount.ToString).InnerText

And yes it returned all 3 again

Thanks

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:un**************@TK2MSFTNGP10.phx.gbl...

Then iterate over /Sections/EMails/* elements:

m_nodelist = m_xmld.SelectNodes("/Sections/EMails/*")

and get InnerText of each one.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com

Nov 12 '05 #5
Well I gave up trying to load using the For Each method decided to use this
method which now allows me at add as many as I wish :-)

Dim reader As New XmlTextReader(m_strXMLPath)

While reader.Read()

If reader.Name.ToUpper = "ADDRESS" Then

strEmailText = reader.ReadInnerXml.ToString

End If

End While reader.Close()

Works like a charm

Thanks
Nov 12 '05 #6

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

Similar topics

1
by: John Martin | last post by:
Hi all, I have a situation where I have a large XML file that controls various aspects of an ASP.NET web application. Ideally, I'd like to keep a single copy of the XML in memory as an...
2
by: Jessard | last post by:
Hi all, I am having trouble reading an XML document in and looping through it's nodes in VB.NET. The error is specific, it is: "There is no Unicode byte order mark. Cannot switch to Unicode."...
1
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
4
by: Oliver Sturm | last post by:
I have an XML file that contains fragments, meaning there's no root element. Node names are in my own "test" namespace. Looks like this: <test:info date="...">Content</test:info> <test:info...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
9
by: Xarky | last post by:
Hi, I am writing an XML file in the following way. Now I need to read again that file to retrieve data such as Name and Age. Can someone help me out. Thanks in Advance ...
2
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate>...
6
by: cj | last post by:
I'm doing something wrong in the reading of this file. I think the rest will work but it keeps telling me something else is using the file. Nothing is. Any ideas? Private Sub...
1
by: davidjohnlong | last post by:
Hi, I'm currently trying to display a XML file within a ASP page, although get the following error when trying to select one of the notes... the node is called: <content:encoded> This is the...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
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
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.