Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析xml字符串时路径中存在非法字符_Xml_Vb.net - Fatal编程技术网

解析xml字符串时路径中存在非法字符

解析xml字符串时路径中存在非法字符,xml,vb.net,Xml,Vb.net,我很难解析cc终端发回的一些简单xml数据 以下是我得到的数据: "<PLCardPresent>0</PLCardPresent><PLEntryMode>1</PLEntryMode><PLNameOnCard>FRANKINSON/FRANK </PLNameOnCard><AmountDue>0</AmountDue><TipAmount>0</TipAmount>&l

我很难解析cc终端发回的一些简单xml数据

以下是我得到的数据:

"<PLCardPresent>0</PLCardPresent><PLEntryMode>1</PLEntryMode><PLNameOnCard>FRANKINSON/FRANK </PLNameOnCard><AmountDue>0</AmountDue><TipAmount>0</TipAmount><CashBackAmout>0</CashBackAmout><MerchantFee>0</MerchantFee><TaxAmount>0</TaxAmount><ExpDate>1219</ExpDate><ECRRefNum>666</ECRRefNum>"
我的方法:

  Protected Function ReturnXmlValue(ByVal myXDoc As Xml.XmlDocument, ByVal field As String) As String
    Dim retval As String = String.Empty

    Try

      Dim node As Xml.XmlNodeList = myXDoc.GetElementsByTagName(field)
      If node IsNot Nothing And node.Count > 0 Then
        retval = node.Item(0).InnerText
      End If

    Catch ex As Exception
      WriteException(ex)
      Throw
    End Try

    Return retval
  End Function
错误发生在加载xml文档时

我不是用正确的方法分析这个吗

其他信息

因为有人建议我检查空终止符,所以我做了以下更改,我希望这就是我的意思:

   Dim test As String = r.ExtData.Replace(ControlChars.NullChar, String.Empty)
   Dim myXmlDoc As New XmlDocument
   myXmlDoc.Load(test)
我仍然收到我在标题中提到的错误

至于什么是r.ExtData,是以我在上面强调的数据行开始的

Dim r As PaymentResponse = posl.PaymentResponse
这给了我类似的东西:


您的字符串不是有效的XML

XML需要有一个根元素。您的根级别上有许多XML元素:

<PLCardPresent>0</PLCardPresent>
<PLEntryMode>1</PLEntryMode>
<PLNameOnCard>FRANKINSON/FRANK </PLNameOnCard>
<AmountDue>0</AmountDue>
<TipAmount>0</TipAmount>
<CashBackAmout>0</CashBackAmout>
<MerchantFee>0</MerchantFee>
<TaxAmount>0</TaxAmount>
<ExpDate>1219</ExpDate>
<ECRRefNum>666</ECRRefNum>

您用来加载XML数据的
r.ExtData
是什么?我在帖子中回复了你们两位。谢谢你的评论。你使用了错误的方法
Load
接受文件名,而不是XML字符串。使用
LoadXml
从stringI加载我做了您建议的两项更改,效果非常好。太好了!
<PLCardPresent>0</PLCardPresent>
<PLEntryMode>1</PLEntryMode>
<PLNameOnCard>FRANKINSON/FRANK </PLNameOnCard>
<AmountDue>0</AmountDue>
<TipAmount>0</TipAmount>
<CashBackAmout>0</CashBackAmout>
<MerchantFee>0</MerchantFee>
<TaxAmount>0</TaxAmount>
<ExpDate>1219</ExpDate>
<ECRRefNum>666</ECRRefNum>
<root>
    <PLCardPresent>0</PLCardPresent>
    <PLEntryMode>1</PLEntryMode>
    <PLNameOnCard>FRANKINSON/FRANK </PLNameOnCard>
    <AmountDue>0</AmountDue>
    <TipAmount>0</TipAmount>
    <CashBackAmout>0</CashBackAmout>
    <MerchantFee>0</MerchantFee>
    <TaxAmount>0</TaxAmount>
    <ExpDate>1219</ExpDate>
    <ECRRefNum>666</ECRRefNum>
</root>
xml.Load(filename); // Filename as string
xml.LoadXml(xmlcontent); // XML as string