caoimhincryan
asked on
Ampersand & issues Javascript
Hi all,
This question is a follow on as such from a previous question I asked: https://www.experts-exchange.com/questions/23292957/Read-from-xml-file.html
I am returning a string but sometime there is an ampersand(&) in the string returned from the xml file and it throws an error for me.
result = objXML.selectSingleNode("/ /configura tion/compo nent[@name ='AnotherC omponentLi nks']/item [@name='"+ v+"']").ge tAttribute ("value");
Any one got any ideas?
The workaround I have is to replace '&' with 'AMPERSAND' in the xml file and then do a .replace("AMPERSAND", "&") once i have got:
result = objXML.selectSingleNode("/ /configura tion/compo nent[@name ='AnotherC omponentLi nks']/item [@name='"+ v+"']").ge tAttribute ("value");
This question is a follow on as such from a previous question I asked: https://www.experts-exchange.com/questions/23292957/Read-from-xml-file.html
I am returning a string but sometime there is an ampersand(&) in the string returned from the xml file and it throws an error for me.
result = objXML.selectSingleNode("/
Any one got any ideas?
The workaround I have is to replace '&' with 'AMPERSAND' in the xml file and then do a .replace("AMPERSAND", "&") once i have got:
result = objXML.selectSingleNode("/
ASKER
No that didnt work. You see, v that is passed is only the item name in the component in the XML file. Its the value i need to look at and stop it from throwing an error: See XML below. the value of v is "HRLINK".
Am i making sense?
Am i making sense?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<component name="PVHRLinks">
<item name="HRLink" value="http://www.google.com/search?hl=en&q="/>
</component>
</configuration>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>Am i making sense?
Yes, but the error is because the XML file you created is invalid. You cannot have an ampersand by itself in XML. Meaning, it has to be encoded. You can encoded either as & or &
When you query/retrieve the value, you will get the expected & (instead of &). This is similar/analogous to encoding a newline with \n. You encode tha newline with the two characters \n in a string, but the result on your screen ends up being an actual (invisible/non-printalbe) new line character.
Yes, but the error is because the XML file you created is invalid. You cannot have an ampersand by itself in XML. Meaning, it has to be encoded. You can encoded either as & or &
When you query/retrieve the value, you will get the expected & (instead of &). This is similar/analogous to encoding a newline with \n. You encode tha newline with the two characters \n in a string, but the result on your screen ends up being an actual (invisible/non-printalbe) new line character.
ASKER
That was the issue surely! Thanks alot.
result = objXML.selectSingleNode("/