|
-
May 3rd, 2008, 10:07 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] reading xml file .. description
this is the xml:
Code:
<TEST description="just a test">output</TEST>
with
Code:
Dim _address As XmlNodeList = _doc.GetElementsByTagName("TEST")
_address(0).InnerText
the result will be 'output' .. how can i get the string 'just a test' from description?
thanks in advanced
-
May 3rd, 2008, 10:36 AM
#2
Re: reading xml file .. description
Code:
Dim descriptions As XmlNodeList = _doc.selectNodes("/root/path/TEST/@description")
You can then read it as
Code:
descriptions(0).Value
-
May 3rd, 2008, 10:43 AM
#3
Thread Starter
Hyperactive Member
Re: reading xml file .. description
Last edited by Amien; May 3rd, 2008 at 10:46 AM.
-
May 3rd, 2008, 10:48 AM
#4
Thread Starter
Hyperactive Member
Re: reading xml file .. description
another question .. can this be coded shorter
Code:
Dim _address As XmlNodeList = _doc.GetElementsByTagName("TEST")
Dim _address2 as String =_address(0).InnerText
If _address2 = "N" Then _address2 = "not found"
If _address2 = "Y" Then _address2 = "found"
msgbox(_address2)
Last edited by Amien; May 3rd, 2008 at 11:01 AM.
-
May 3rd, 2008, 02:28 PM
#5
Re: reading xml file .. description
Is there a reason you're continuing to use .GetElementsByTagName despite what was mentioned in post #2?
To answer your question, though:
vb Code:
Dim address As String = String.Empty Dim testNodes As XmlNodeList = doc.GetElementsByTagName("TEST") If testNodes(0).InnerText = "N" Then address = "not found" Else address = "found" End If
-
May 3rd, 2008, 02:40 PM
#6
Thread Starter
Hyperactive Member
Re: reading xml file .. description
 Originally Posted by mendhak
Is there a reason you're continuing to use .GetElementsByTagName despite what was mentioned in post #2?
Yes .. cause some some lines i still use the GetElemetsByTagname, cause those lines dont have a @description added
thanks for the info
-
May 3rd, 2008, 02:43 PM
#7
Re: [RESOLVED] reading xml file .. description
No problem, but I suggest using the .selectNodes and .selectSingleNode method with XPath passed as arguments. I believe they are more efficient than simply getting by tag name.
-
May 3rd, 2008, 03:44 PM
#8
Thread Starter
Hyperactive Member
Re: [RESOLVED] reading xml file .. description
sorry .. still 1 question .. ASP.nET related
Code:
Dim _phonenumber As XmlNodeList =_doc.SelectNodes("/Root/PHONENUMBER")
StatusLabel.Text = StatusLabel.Text & "<tr class='row2'><td>Phonenumber</td><td> " & _phonenumber(0).InnerText & "</td></tr>"
some XML have a phonenumber entry .. but some dont .. if phonenumber is not found _phonenumber(0).InnerText should be empty .. but i get an error instead ..
-
May 3rd, 2008, 03:54 PM
#9
Re: [RESOLVED] reading xml file .. description
Where do I begin... 
1. Don't concatenate HTML for your labels. Have your label simply accept a textual value, let the <tr><td> markup be ready for it around the label.
2. If you only want one value out of some XML and don't need the rest of your node list, then use .SelectSingleNode rather than SelectNodes. There isn't a point to loading an entire node list if you need just one value.
Code:
Dim phoneNode As XmlNode = doc.SelectSingleNode("/Root/PHONENUMBER[1]")
3. Check if the node is Null/Nothing before you attempt to read its .Value/.InnerText.
-
May 3rd, 2008, 03:54 PM
#10
Re: [RESOLVED] reading xml file .. description
Also, please post ASP.NET questions in the ASP.NET forum.
http://www.vbforums.com/forumdisplay.php?f=31
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|