[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
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
Re: reading xml file .. description
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)
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
Re: reading xml file .. description
Quote:
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
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.
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 ..
Re: [RESOLVED] reading xml file .. description
Where do I begin... :sick:
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.
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