Link to home
Start Free TrialLog in
Avatar of PedroG
PedroG

asked on

MSXML: html in a node

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.
Avatar of peteyhiggins
peteyhiggins

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
Avatar of PedroG

ASKER

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
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 :)
ASKER CERTIFIED SOLUTION
Avatar of dannic
dannic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PedroG

ASKER

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