Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating XML with an ampersand in data #16

Closed
GoogleCodeExporter opened this issue Nov 9, 2015 · 12 comments
Closed

Evaluating XML with an ampersand in data #16

GoogleCodeExporter opened this issue Nov 9, 2015 · 12 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. read in feed that has ampersands within data
2. execute jsfiddle with feed
3. parse error on execution

What is the expected output? What do you see instead?

JSON with correctly escaped ampersand to be able to replicate XML feed which 
includes many ampersands within data.
See instead a parse error.

What version of the product are you using? On what operating system and
browser version?

x2js 1.1.2

Please provide any additional information below.

Original issue reported on code.google.com by ad...@aidsark.org on 16 Oct 2013 at 11:00

@GoogleCodeExporter
Copy link
Author

[deleted comment]

1 similar comment
@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

This is an issue for  data including    &    

Original comment by ad...@aidsark.org on 16 Oct 2013 at 11:16

@GoogleCodeExporter
Copy link
Author

Investigating

Original comment by abdulla....@gmail.com on 16 Oct 2013 at 12:28

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Thanks - here's a sample feed to trial ...

http://corcoransunshine.com/newdevxml/447NewDevs.xml

Original comment by ad...@aidsark.org on 16 Oct 2013 at 12:33

@GoogleCodeExporter
Copy link
Author

I've checked it with v1.1.3 
(https://code.google.com/p/x2js/source/browse/xml2json.js) and it looks like 
working for me.

Example with your feed:

     function loadXMLDoc(dname) {
        if (window.XMLHttpRequest) {
            xhttp=new XMLHttpRequest();
        }
        else {
            xhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET",dname,false);
        xhttp.send();
        return xhttp.responseXML;
    }


    var xmlDoc = loadXMLDoc("447NewDevs.xml");
    var x2js = new X2JS();
    var jsonObj = x2js.xml2json(xmlDoc);

Could you please provide your sample / code where is a problem?

Original comment by abdulla....@gmail.com on 16 Oct 2013 at 12:55

@GoogleCodeExporter
Copy link
Author

Was testing via the JS Fiddle you built - inputting the XML from in textarea 
for XML field (together with & data)...

Original comment by ad...@aidsark.org on 16 Oct 2013 at 1:03

@GoogleCodeExporter
Copy link
Author

Ouch. Now I understand what you mean. You can't enter '&' to that demo, because 
it is not suitable demo for XML escaping. 
You should have valid well formatted XML string or DOM object for input.
For example, this is not valid XML in string form:
"<textNode>First & Child</textNode>". 
Valid and well-formed XML string form is "<textNode>First & Child</textNode>"
If you have manually enterered XML in string form, you should escape it value 
(because it is required by XML standard).

You should escape only XML node value, not full XML document (in a string 
form). 
For example:
"<textNode>First <> Child</textNode>" should be
"<textNode>First <> Child</textNode>"

Well, this is a not x2js issue. It is just about valid XML string formatting :)
Let me know if you had any other questions.

Original comment by abdulla....@gmail.com on 16 Oct 2013 at 1:28

  • Changed state: WontFix

@GoogleCodeExporter
Copy link
Author

right - I was using &  (not just & as it isn't valid XML)  ... the fiddle   
doesn't work with & values.

Original comment by ad...@aidsark.org on 16 Oct 2013 at 1:37

@GoogleCodeExporter
Copy link
Author

Ok, you entered you test data with & in the input or in the HTML window code 
frame (at fiddle)?
You can't do it with HTML window code. Actually I'm just lazy and shouldn't 
have fill textarea in that style (because it's not valid HTML).
If you enter test data with & in the textarea (bottom-right frame at fiddle) 
you will see it's working :)

Original comment by abdulla....@gmail.com on 16 Oct 2013 at 1:47

@GoogleCodeExporter
Copy link
Author

right - thanks!

Original comment by ad...@aidsark.org on 16 Oct 2013 at 1:51

@GoogleCodeExporter
Copy link
Author

NP. I'll think about update demo to avoid misunderstandings.

Original comment by abdulla....@gmail.com on 16 Oct 2013 at 2:09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant