且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解析xml并删除不需要的标签

更新时间:2022-10-14 19:16:11

我不确定您对输出xml的期望是什么,请查看以下链接以了解您可以尝试的不同方式

使用Linq to XML [ ^ ]

使用XSLT处理XML [ ^ ]

使用正则表达式 [ ^ ]


Hi everyone, I am not well versed in xml and am having a problem. I want to display an xml file in a form, but not the first few lines. Here is the xml:

<pre lang="xml"><?xml version="1.0"?>
<!--This is a host terminal response-->
<RESPONSE xmlns="x-schema:C:\fp\swdir\Content\emulation-schema.xmlK">
  <LINE INDEX="1"><![CDATA[VJ5L6E/SF QSBSB DBAYSF  AG 49837045 26NOV]]><CARRIAGE_RETURN/></LINE>
  <LINE INDEX="2"><![CDATA[ 1.1FOSTER/SCOTT ]]><CARRIAGE_RETURN/></LINE>




All I'm looking to do is eliminate everything but the portions after the CDATA tags.

Here is what I've tried along with dozens of attempsts:

doc.LoadXml(strResp)


        For Each node As XmlNode In nodeList
            'TextBox1.Text = TextBox1.Text & node.SelectSingleNode("RESPONSE").InnerText
            TextBox1.Text = TextBox1.Text & node.SelectSingleNode("RESPONSE xmlns").InnerText
        Next node




Any help would be greatly appreciated. Thanks.
John

I'm not sure what exactly you expected as output xml, check below links for different ways you can try
Using Linq to XML[^]
processing XML with a XSLT[^]
Using regex[^]