如何从xml响应文本中获取段文本 [英] how get a segment text from a xml response text

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

问题描述

Hello社区



我有以下查询。我正在使用Visual Basic 2008制作的PROYECO,使用visual studio 2008.



该项目是运行一个Web服务,我收到的回应是XML格式的字符串



在数据周期内引入以下行的账单。



< pre lang =xml> < FechaXML xmlns = xxxx://xxx.xxxxxxxxx.xx/xxxxxx\"> 2014-10-30T17:01:49 < / FechaXML > < 文件 ID = 6078729 xmlns = xxxx://xxx.xxxxxxxxx.xxx/xxxxxx > < LineasFactSinOc > < / LineasFactSinOc > < Encabezado > < IdDoc > < ; TipoDoc & gt; FC < / TipoDoc > ; < NumDoc > 3257 < / NumDoc > < FolioUnico > 0101- 368247 < / FolioUnico > < span class =code-keyword>< FchTransaccion > 2014-05- 30T19:23:08 < / FchTransaccion > < FchEmis > 2014-01-09 < / FchEmis > < FchVenc > 2014-04-12 < / FchVenc > < FchRecepcion > 2014-01-21 < / FchRecepcion > < FchEstimadaPago > 2014-02-21 < / FchEstimadaPago > < Comentarios > Nombre用户:SARANCIBIAA号码......



它是xml文本的一部分,用于解释我要提取的事实



我使用以下代码获取该部分

 documentoXML.LoadXml(testxml.InnerXml)
NodeLista = documentoXML.FirstChild.FirstChild.FirstChild.ChildNodes
< span class =code-keyword>对于 每个 Nodo NodeLista
Cuenta = Cuenta + 1
CuentaNodo = CuentaNodo + 1
Dim Resultado 作为 字符串

如果 Nodo.LocalName = ICDoc 然后
Resultado = Nodo.InnerXml.Substring( 83 23
MsgBox(Resultado





将xml文本分配给变量Resultado。



我怎样才能获得文件ID部分=6078729只有引号中的值?这个值的变化会增加或减少数字的位数,可以是12,10000...有没有办法计算从第一个到第二个引号的数字?



如果需要了解问题的信息,请通知或咨询谢谢

解决方案

  dim  xl  as   string  =   < Categories> +   < category name =a> +  < SubCategory> 1< / SubCategory> +  < SubCategoryName> name1< / SubCategoryName> +  < / category> +  <小号pan class =code-string>< category name =b> +  < SubCategory> 2< / SubCategory> +  < SubCategoryName> name2< / SubCategoryName> ; +  < / category> +  < / Categories> 
dim xdoc as new XmlDocument()
xdoc.LoadXml(xl)
For Each node As XmlNode xdoc.SelectNodes( // category
Console.WriteLine(node.Attributes( name)。值)
下一页



希望你明白了


我提出了解决方案





  Dim  s  As   String  =   

< span class =code-keyword> Dim doc As XmlDocument()
doc.LoadXml(testxml.InnerXml)
reader = XmlNodeReader(doc)
reader.Read()
选择 案例 reader.NodeType
案例 XmlNodeType.Element
s = reader.Name
如果 s = Documento 然后
Dim 属性 As String =
Attribute = reader.GetAttribute( ID
MsgBox( 文档ID = + AtTribute)
结束 如果


Hello community

I have the following query. I'm working with a PROYECO made ​​in visual basic, using visual studio 2008.

The project is to run a web service, which I receive in response a string in XML format

Within the data cycles to bring in a bill the following line.

<FechaXML xmlns = "xxxx: //xxx.xxxxxxxxx.xx/xxxxxx"> 2014-10-30T17: 01: 49 </ FechaXML> <document ID = "6078729" xmlns="xxxx://xxx.xxxxxxxxx.xxx/xxxxxx"><LineasFactSinOc></LineasFactSinOc><Encabezado><IdDoc><TipoDoc>FC</TipoDoc><NumDoc>3257</NumDoc><FolioUnico>0101-368247</FolioUnico><FchTransaccion>2014-05-30T19:23:08</FchTransaccion><FchEmis>2014-01-09</FchEmis><FchVenc>2014-04-12</FchVenc><FchRecepcion>2014-01-21</FchRecepcion><FchEstimadaPago>2014-02-21</FchEstimadaPago><Comentarios>Nombre User: SARANCIBIAA Number ...


It is a part of xml text, to explain the fact that I want to extract

I use the follwing code to Get That part

documentoXML.LoadXml(testxml.InnerXml)
           NodeLista = documentoXML.FirstChild.FirstChild.FirstChild.ChildNodes
           For Each Nodo In NodeLista
               Cuenta = Cuenta + 1
               CuentaNodo = CuentaNodo + 1
               Dim Resultado As String

                     If Nodo.LocalName = "ICDoc" Then
                      Resultado = Nodo.InnerXml.Substring(83, 23)
                      MsgBox(Resultado



The xml text is assigned to the variable "Resultado".

How do I can get the Document ID part = "6078729" only the value that is in quotes? that this value changes increase or decrease the number of digits, can be "12", "10000" ... is there any way to count the digits from the first to the second quote?

if information needed to understand the problem please notify or consult thanks

解决方案

dim xl as string = "<Categories>" + "<category name=""a"">" + "<SubCategory>1</SubCategory>" + "<SubCategoryName>name1</SubCategoryName>" + "</category>" + "<category name=""b"">" + "<SubCategory>2</SubCategory>" + "<SubCategoryName>name2</SubCategoryName>" + "</category>" + "</Categories>"
dim xdoc as new XmlDocument()
xdoc.LoadXml(xl)
For Each node As XmlNode In xdoc.SelectNodes("//category")
    Console.WriteLine(node.Attributes("name").Value)
Next


hope you got it


I made the solution


Dim s As String = ""

Dim doc As New XmlDocument()
doc.LoadXml(testxml.InnerXml)
reader = New XmlNodeReader(doc)
While reader.Read()
      Select Case reader.NodeType
      Case XmlNodeType.Element
          s = reader.Name
      If s = "Documento" Then
         Dim Attribute As String = ""
         Attribute = reader.GetAttribute("ID")
         MsgBox("Document ID =" + AtTribute)
     End If


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

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