Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<ErrCodes>
     <Error id="102">Name missing from this item in catalog.</Error>
</ErrCodes>


the function i have been trying to create is below but

VB
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

VB
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900