Error Processing XML Content with the JavaScript API

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2008 08:05 PM
RhinoScript supports ECMAscript for XML (E4X). I created a document under Company Home using DM Forms (XForms and an XML Schema definition for ProductApplication). In the JavaScript file for my Web Script I am trying to select Documents under Company Home that are of type text/xml and have an element within the node's XML content set to "Some Application".
I am getting an error when I try to parse the content into an XML object with this statement: var doc = new XML(node.content);
The error I get is: org.mozilla.javascript.EcmaError - TypeError: Cannot parse XML: The processing instruction target matching "[xX][mM][lL]" is not allowed. (AlfrescoScript#14)
node.content is:
If I remove the processing-instruction <?xml …?> it works fine. I don't want to code around this problem. I set XML.ignoreProcessingInstructions=true, but it still fails to execute with the same error.
I am using Alfresco Community 2.9B with the out-of-the-box configuration.
I am getting an error when I try to parse the content into an XML object with this statement: var doc = new XML(node.content);
The error I get is: org.mozilla.javascript.EcmaError - TypeError: Cannot parse XML: The processing instruction target matching "[xX][mM][lL]" is not allowed. (AlfrescoScript#14)
node.content is:
<?xml version="1.0" encoding="UTF-8"?><tns:ProductApplication xmlns:alf="http://www.alfresco.org" xmlns:chiba="http://chiba.sourceforge.net/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:null="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org/ProductApplication" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><tns:application>Some Application</tns:application><tns:product><p>Some Product</p></tns:product><tns:crossSellRank>1</tns:crossSellRank></tns:ProductApplication>
If I remove the processing-instruction <?xml …?> it works fine. I don't want to code around this problem. I set XML.ignoreProcessingInstructions=true, but it still fails to execute with the same error.
I am using Alfresco Community 2.9B with the out-of-the-box configuration.
Labels:
- Labels:
-
Archive
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2008 08:15 PM
Here's why!
Exerpt from the Mozilla Developer Center (https://developer.mozilla.org/en/E4X)
Alfresco Workaround:
Edit 11/2/2008 10:14PM: Be careful that you don't include any whitespace/newline characters before the first XML element in the node.content, otherwise new XML("\r\n<test>Test Successful</test>") will create a blank XML text node, which can be very confusing, but it's part of the E4X specification.
Exerpt from the Mozilla Developer Center (https://developer.mozilla.org/en/E4X)
E4X doesn't support parsing XML declaration ( <?xml version=…?>) (see bug 336551 ). You may get SyntaxError "xml is a reserved identifier" (despite the XML being in a string).
Workaround:var response = xmlhttprequest.responseText; // bug 270553response = response.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551var e4x = new XML(response);
Alfresco Workaround:
var content = new XML(node.content.replaceAll("(?s)<\\?xml .*?\\?>\\s*", "")); // Workaround: Mozilla Bug 336551
Edit 11/2/2008 10:14PM: Be careful that you don't include any whitespace/newline characters before the first XML element in the node.content, otherwise new XML("\r\n<test>Test Successful</test>") will create a blank XML text node, which can be very confusing, but it's part of the E4X specification.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2014 11:26 AM
HI
I've used this to remove XML first line.
var content = new XML(node.content.replaceAll("(?s)<\\?xml .*?\\?>\\s*", ""));
It works fine.
Now I need to remove the xmlns form my tag.
I found some clues on forums but nothing works for me.
Any help with this please?
I've used this to remove XML first line.
var content = new XML(node.content.replaceAll("(?s)<\\?xml .*?\\?>\\s*", ""));
It works fine.
Now I need to remove the xmlns form my tag.
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00"><NFe xmlns="http://www.portalfiscal.inf.br/nfe">
I found some clues on forums but nothing works for me.
Any help with this please?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2008 11:22 PM
Here are some great Tutorials and Documents on XML Processing with E4X (ECMAScript for XML aka JavaScript for XML)
W3Schools E4X Tutorial: http://www.w3schools.com/e4x/default.asp
DevX Article: http://www.devx.com/webdev/Article/33393/1763/page/1
E4X Specification: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-357.pdf
W3Schools E4X Tutorial: http://www.w3schools.com/e4x/default.asp
DevX Article: http://www.devx.com/webdev/Article/33393/1763/page/1
E4X Specification: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-357.pdf
