[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

& 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.
                  
0
unceasing
Asked:
unceasing
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now