I work with Android, and i want to parse an xml page .The source code contains a section CDATA.This section is displayed in my simulator.I want to filter the tags and display only the content.The sorce code of xml is like
I want to have just "Alex"Code:<customer> <lastname> - <![CDATA[ Alex ]]> </lastname> </customer>
This is my code javascript to parse my document xml.
Code:// File: readXML.js // Start function when DOM has completely loaded $(document).ready(function(){ // Open the students.xml file $.get("http://www.patisserie-orient.fr/prestashop/prestashop/en/api/customers/2",{},function(xml){ // Build an HTML string myHTMLOutput = ''; myHTMLOutput += '<table width="98%" border="1" cellpadding="0" cellspacing="0">'; myHTMLOutput += '<th>Name</th><th>Age</th><th>Phone</th><th>SSN</th>'; // Run the function for each student tag in the XML file $('customer',xml).each(function(i) { studentName = $(this).find("lastname").text(); studentAge = $(this).find("lastname").text(); studentPhone = $(this).find("lastname").text(); studentSSN = $(this).find("lastname").text(); studentPost = $(this).find("lastname").text(); // Build row HTML data and store in string mydata = BuildStudentHTML(studentName,studentAge,studentPhone,studentSSN,studentPost); myHTMLOutput = myHTMLOutput + mydata; }); myHTMLOutput += '</table>'; // Update the DIV called Content Area with the HTML string $("#ContentArea").append(myHTMLOutput); }); }); function BuildStudentHTML(studentName,studentAge,studentPhone,studentSSN,studentSE){ // Check to see if their is a "post" attribute in the name field if ((studentPost) != undefined){ studentPostHTML = "<strong>(" + studentPost + ")</strong>"; } else { studentPostHTML = ""; } // Build HTML string and return output = ''; output += '<tr>'; output += '<td>'+ studentName + studentPostHTML + '</td>'; output += '<td>'+ studentAge +'</td>'; output += '<td>'+ studentPhone +'</td>'; output += '<td>'+ studentSSN +'</td>'; output += '</tr>'; return output; }


Reply With Quote

Bookmarks