帮助从xml获取数据 [英] help getting data from xml

查看:51
本文介绍了帮助从xml获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一家公司的xml文件及其错误代码,我在获取内部价值方面遇到了问题。我需要的是错误代码的文本,如果有人可以帮助我,这将是伟大的。我公司的一个要求是xml必须是一个嵌入式资源。



  <   ErrCodes  >  
< 错误 id = 102 > 名称目录中的此项目缺失。< /错误 > ;
< / ErrCodes >





我试图创建的功能在下面但是



 功能 Readerrors( ByVal  sError)
Dim str =
Dim strResources As String = System.Reflection.Assembly.GetExecutingAssembly()。GetName()。Name& 。Errors.xml
Dim document As XPathDocument = XPathDocument(System.Reflection.Assembly.GetExecutingAssembly()。GetManifestResourceStream( strResources))
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim 节点作为 XPathNavigator = navigator.SelectSingleNode( // ErrCodes [@id =& sError& ]
str = node.InnerXml
返回 str
结束 功能

解决方案

VB.NET中的XML文件解析 [ ^ ]

http://forum.coolwebawards.com/threads/121-Read-XML -using-VB.NET [ ^ ]

http:// vb.net-informations.com/xml/open-xml-vb.net.htm [ ^ ]


 导入 System.Xml 

函数 ReadErrors()
Dim reader As XmlTextReader = XmlTextReader( Errors.xml
执行 (reader.Read())
选择 案例 reader.NodeType
案例 XmlNodeType.Element ' start元素忽略它
案例 XmlNodeType.Text
return (reader.Value)' < span class =code-comment>这是你想要的值

Case XmlNodeType.EndElement ' 元素结尾忽略它
结束 选择
循环

Zachary,
播放 此代码 获取您需要的内容,但我认为 是您的答案。


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

解决方案

XML File Parsing in VB.NET[^]
http://forum.coolwebawards.com/threads/121-Read-XML-using-VB.NET[^]
http://vb.net-informations.com/xml/open-xml-vb.net.htm[^]


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.


这篇关于帮助从xml获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆