我正在VB中编程。当前在网页上显示一些XML。我想显示一个可点击的链接。所以我尝试了:
Dim objXml As System.Xml.XmlDocument = New System.Xml.XmlDocument
objXml.LoadXml(pInfo.AsXml)
Dim outerXML = Replace(objXml.OuterXml(), "<MID>someText</MID>", "<MID><![CDATA[<a href='https://www.google.com'>Click me</a>]]></MID>")
但是它实际上只显示所有文本,并且不格式化CDATA中的html:
<MID><a href='https://www.google.com'>Click me</a></MID>
它应该显示的是:
<MID>Click me</MID>
任何想法为什么这不起作用?
您可以尝试使用双引号:
Dim outerXml as String = Replace(objXml.OuterXml(), "<MID>someText</MID>", "<MID><![CDATA[<a href=""https://www.google.com"">Click me</a>]]></MID>")
或
Dim outerXml as String
outerXML = Replace(objXml.OuterXml(), "<MID>someText</MID>", "<MID><![CDATA[<a href=""https://www.google.com"">Click me</a>]]></MID>")
您也可以将xml.WriteCdata与xml writer一起使用
https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter.writecdata?view=netframework-4.8