简体   繁体   中英

Display a clickable link out of a XML file on a website with CDATA

I am programming in VB. And currently displaying some XML on a Webpage. I would like to display a clickable link. So I tried:

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>")

But it actually displays just all the text and does not format the html inside CDATA:

<MID><a href='https://www.google.com'>Click me</a></MID>

All it should display is:

<MID>Click me</MID>

Any ideas why this is not working?

You can try like so with double quotes:

Dim outerXml as String = Replace(objXml.OuterXml(), "<MID>someText</MID>", "<MID><![CDATA[<a href=""https://www.google.com"">Click me</a>]]></MID>")

or

Dim outerXml as String
outerXML = Replace(objXml.OuterXml(), "<MID>someText</MID>", "<MID><![CDATA[<a href=""https://www.google.com"">Click me</a>]]></MID>")

You could also use xml.WriteCdata with xml writer

https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter.writecdata?view=netframework-4.8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM