Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I recieved an xml file from a company with their error codes and i'm having problems getting the inner value. what i need is the Text for the error code if someone could help me that would be great. The one requierment my company has is the xml has to be an embeded resource.
 
<ErrCodes>
     <Error id="102">Name missing from this item in catalog.</Error>
</ErrCodes>
 
the function i have been trying to create is below but
 
Function Readerrors(ByVal sError)
    Dim str = ""
    Dim strResources As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name & ".Errors.xml"
    Dim document As XPathDocument = New XPathDocument(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(strResources))
    Dim navigator As XPathNavigator = document.CreateNavigator()
 
    Dim node As XPathNavigator = navigator.SelectSingleNode("//ErrCodes[@id=" & sError & "]")
    str = node.InnerXml
    Return str
End Function
Posted 25-Oct-12 11:38am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Imports System.Xml
 
Function ReadErrors()
Dim reader As XmlTextReader = New XmlTextReader("Errors.xml")
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'start element ignore it
Case XmlNodeType.Text
return (reader.Value) 'this is the value that you want
Case XmlNodeType.EndElement 'end of element ignore it
End Select
Loop
 
Zachary,
play with this code to get what you need, but I think this is your answer.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100