& problem in xml

I have a file xml1.xml which has some xhtml in an attribute of  an element.

xml1.xml
<page id=1 title="title" text="&lt;p&gt; some text which has &amp; character &lt;p&gt;t"/>

I have an xsl which is trying to load the XHTML in the "text"  attribute into a different xml by passing it to a javascript file using a js function

function getNodesFromXmlString(str)
                  {
                        
                              
                            try
                            {
                                  var xmlDoc = new ActiveXObject( "MSXML2.DOMDocument.4.0" );
                                  xmlDoc.async = false
                                  str=unescape(str);
                                    xmlDoc.loadXML(str);
                                    if (xmlDoc.parseError.errorCode != 0) {
                                          xmlDoc.loadXML("<error>"+xmlDoc.parseError.reason + xmlDoc.parseError.line +"</error>");
                                        return xmlDoc;
                                    }
                                    else
                                    {
                                          return xmlDoc;
                                    }
                            }catch(e){
                                 try
                                 {
                                        var xmlDoc = new ActiveXObject( "MSXML2.DOMDocument.4.0" );
                                        xmlDoc.loadXML("<error>"+e.message+"</error>");
                                        return xmlDoc;
                                    }catch(e){
                                          return "";
                                  }
                            }
                           
                  }

I'm getting an error when the xml has "&" character in the attribute.

tried replacing the &amp; with &#38; still does not work.  The xmlDoc.parseError.reason I get in such a case is "A semicolon character was expectred.

Any help is greatly appreiciated.
                  
unceasingAsked:
Who is Participating?
 
Rouneh10Commented:
You may want to put text into a node by itself like so:

<page id="1" title="title">
  <pagetext><![CDATA[testdata with an & character]]></pagetext>
</page>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.