We help IT Professionals succeed at work.

MSXML: html in a node

PedroG
PedroG asked
on
Hy,

I'm using Microsof XML 3 to build XML files and then tranform them to html using XSL.

My problem is the folowing :

One of my XML nodes content is HTML code.

I'm creating the node using the folowing code :

Set XMLItem = XMLDom.createElement("Text")
XMLItem.Text = oRs("Text")
XMLConteudo.appendChild XMLItem

oRs("Text") is a recordset field thas as HTML code for ex:(<span class="paintext">This is a test</span>)

My problem is that the xml content isn't the same of the recordset field. The parser is encoding the string. I need to place the string as is.

I also tryed to use cdata like this
XMLItem.Text = "<![CDATA[" & oRs("Text") &"]]>"

but the <![ chars get encoded to.

Is there any way to solve this problem????

Please this is realy urgent.
Comment
Watch Question

Try using the replace() function in VB to turn the < and > into regular expressions.  Then XML should be able to read them properly without thinking you're closing or opening XML tags.

The regular expressions are : &lt; for < and &rt; for >

So in VB, use this code:

dim sText as string

sText = oRS("Text").Value

sText = replace(sText, "<", "&lt;")
sText = replace(sText, ">", "&rt;")

XMLItem.Text = sText

Give that a try

Author

Commented:
it doesn't work

that way insted of havig a <span in my xml i get a &lt;span wich is exactly what the parser was doing by itself.

I need to have the text in such a way that i can use
<xsl:value-of select="content\Text"/> in my xsl and it will output the html code

Commented:
try this...

    Set X = New DOMDocument30
    sTemp = XDom.xml
    sTemp = Replace(sTemp, "&lt;", "<")
    sTemp = Replace(sTemp, "&gt;", ">")
    X.loadXML sTemp

take the xml from the first dom doc object, do the replacements, then load the new string into a second dom doc object.

the only requirement, is that you *still* need well formatted xml.  otherwise, it won't load...

better make sure your HTML is right :)
Commented:
Try to create your node using a CDATA Section

This should work if...
' XMLItem is an instance of MSXML2.IXMLDOMNode
' AND
' XMLDom is an instance of  MSXML2.IXMLDOMNode

Dim objTmpNode As MSXML2.IXMLDOMNode
Set XMLItem = XMLDom.createElement("Text")
Set objTmpNode = XMLDom.createCDATASection(oRs("Text"))
Set objTmpNode = XMLItem.appendChild(objTmpNode)
XMLConteudo.appendChild XMLItem

Good luck!

Author

Commented:
Thanks dannic,

That realy solved my problem, i just had to made a minor change in my xsl.

Now it's realy working very nicely

Explore More ContentExplore courses, solutions, and other research materials related to this topic.