Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:49:55+00:00 2026-05-30T16:49:55+00:00

I am trying to load an XML file, but the content in the XML

  • 0

I am trying to load an XML file, but the content in the XML has ampersands in it. Is there a way to escape them in the code? Rather than editing the actual XML file? All the other answers I have found have suggested that I edit the code before I load it with Javascript, but that is not an option for me because I am pulling it from a database that is always changing.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:49:56+00:00Added an answer on May 30, 2026 at 4:49 pm

    From what I get from you question is that you want to replace the ampersands? If so I actually just dealt with this issue the other day.

    The way I approached it was I loaded the XML File, then I took the
    response.Text, which converts the XML file object into a string, and encoded that into hex. I then replaced all “%26”, which is the hex for “&”, with “&_amp;” (Take out the underscore! the message converts it into a ‘&’), which XML can understand. I then decoded it and loaded it again as a string. That’s all you have to do. Here is some sample code…

    var x;
    
    function loadXMLFile(xmlFile){
       var xmlhttp = new window.XMLHttpRequest();
       xmlhttp.open("GET",xmlFile,false);
       xmlhttp.send(null);
    
       //encodes the xml, replaces all invalid characters with their hex value, decodes the xml, then parses it.
       var encoded = encodeURIComponent(xmlhttp.responseText);
       var replaced = encoded.replace(/%26/g,"&");  // &
       var decoded = decodeURIComponent(replaced);
    
       //Pass in the new XML string, which turns into an XML Object which you can parse.
       parser=new DOMParser();
       xmlDoc=parser.parseFromString(decoded,"text/xml");
    
       x=xmlDoc.getElementsByTagName("Sample_Tag");
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the following code # LOAD XML FILE $XML = new
i'm trying to load some elements from a xml file. but it XDocument.Load seems
I am trying to load an xml file that is stored as a resource
I'm trying to load a simple Xml file (encoded in UTF-8): <?xml version=1.0 encoding=UTF-8?>
I'm trying to load Gravatars into Flash. Luckily, they provided a crossdomain.xml file at
I am trying to load a very basic XML document but everytime I get
I'm facing a rather strange Issue when trying to load data from an XML-Webservice.
I am currently trying to load a slightly large xml file into a dataset.
I'm trying to parse an XML file using PHP, but I get an error
I'm trying to write on xml file. but my server have DOM as disabled.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.