0

I am trying to alert the value of $xml.html(), but i am getting undefined. There is my code

var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
$xml.find('TaxPayer').text('shri');
alert($xml.html());
4
  • var xml is not valid syntax... script terminates Commented Feb 28, 2014 at 11:16
  • I have changed the variable name but it still not working, can you tell me the solution of this probem. I am editing the question Commented Feb 28, 2014 at 11:20
  • @AASHUTOSHSHRIVASTAVA: what you exaclty want to be alert ?? also check this jsfiddle.net/9Hd5T Commented Feb 28, 2014 at 11:30
  • I want to alert xml file before & after changes. Commented Feb 28, 2014 at 11:32

2 Answers 2

2

JS FIDDLE DEMO

JS FIDDLE DEMO 2

var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
alert($xml.find('xml').html());
alert($xml.find('xml').text());

var xml ='<xml version="1.0" encoding="UTF-8" standalone="no"><TaxPayer><PersonalInformation><FirstName>aashu</FirstName></PersonalInformation></TaxPayer></xml>';
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml);
alert($xml.find('xml').html());
alert($xml.find('xml').text());
$xml.find('FirstName').text('satinder');

alert($xml.find('xml').html());
alert($xml.find('xml').text());
Sign up to request clarification or add additional context in comments.

7 Comments

is only alert the actual value not modify value. I want to alert/print both the value of xml
@AASHUTOSHSHRIVASTAVA Try the 2nd fiddle demo. There's a lot of alerts, but it does show the value changed.
@AASHUTOSHSHRIVASTAVA: check the demo 2, it clearly alert before and after modification, 1st time is asshu and 2nd time it alert satinder , dude check properly
Thanks Satinder. Can you help me to print both the xml file in HTML page
@AASHUTOSHSHRIVASTAVA That's not how SO works. If you have another question then please ask another question, otherwise this page becomes a specific "how do I make MY site do what I want" page.
|
0

Try this

    var xml =$('<XMLDocument />')
    xml.append($('<TaxPayer/>')
               .append($('<PersonalInformation/>')
                       .append($('<FirstName/>').text('aashu')))); 
var xmlDoc = $.parseXML( xml );
var $xml = $( xmlDoc );
alert(xml.html());
xml.find('TaxPayer').find('FirstName').text('shri');
alert(xml.html());

This may help. live demo

5 Comments

What the mean of this answer. Its not related to problem. Please delete it.
@AASHUTOSH SHRIVASTAVA What you actually want to do? When you posting a question specify your problem properly.
I want first print or alert the xml without changes & then print or alert xml with modify value.
@AASHUTOSHSHRIVASTAVA if any of the answer solves your problem, then don't forget to mark as answer. So that will help others
Yes James, I have marked it. this jsfiddle.net/9Hd5T/3 exact thing what i want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.