Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Removing XML Tag

    Hi, I am new to XML. I have a question here. Is it possible to remove the <....> in the example like below. If yes, then is there any php code or function that I can use?

    <catalogue>
    <resource>
    <book>
    <ID>Book 1</ID>
    <date>today</date>
    <retdate>tomorrow</retdate>
    <SID>Student 1</SID>
    </book>
    <book>
    <ID>Book 2</ID>
    <date>today</date>
    <retdate>tomorrow</retdate>
    <SID>Student 4</SID>
    </book>
    </resource>
    </catalogue>

    So, I would like to have my end result as:
    Book 1
    today
    tomorrow
    Student 1

    Book 2
    today
    tomorrow
    Student 4

    Appreciate if anyone of you could answer my doubt.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,354
    Thanks
    23
    Thanked 618 Times in 617 Posts
    Is it possible to remove the <....>
    Yes, but I think your trying to do that because you don't know how to extract (read) the information in a xml file. Removing the tags just destroys the file. Your catalogue file does not have a name, I gave it 'loans.xml' and placed it in the same directory as the following javascript script.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    var txt,x,i;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        xmlDoc=xmlhttp.responseXML;
        txt="";
        x=xmlDoc.getElementsByTagName("ID");
    	y=xmlDoc.getElementsByTagName("date");
    	z=xmlDoc.getElementsByTagName("retdate");
    	p=xmlDoc.getElementsByTagName("SID");
        for (i=0;i<x.length;i++)
          {
          txt=txt + x[i].childNodes[0].nodeValue +"<br />";
    	  txt +=y[i].childNodes[0].nodeValue + "<br />";
    	  txt +=z[i].childNodes[0].nodeValue + "<br />";
    	  txt +=p[i].childNodes[0].nodeValue + "<br /><br />";
          }
        document.getElementById("myDiv").innerHTML=txt;
        document.getElementById("push").style.display = 'none';
        }
      }
    xmlhttp.open("GET","loans.xml",true);
    xmlhttp.send('');
    }
    </script>
    </head>
    
    <body>
    <div id="myDiv"></div>
    <button type="button" id="push" onclick="loadXMLDoc()">Decode xml File</button>
    </body>
    </html>
    It's a little clunky but I think you can see whats going on. As for me I think I'll start to relearn xml and update my code.

  • Users who have thanked sunfighter for this post:

    zhennn (09-15-2012)

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    Yes, but I think your trying to do that because you don't know how to extract (read) the information in a xml file. Removing the tags just destroys the file. Your catalogue file does not have a name, I gave it 'loans.xml' and placed it in the same directory as the following javascript script.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    var txt,x,i;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        xmlDoc=xmlhttp.responseXML;
        txt="";
        x=xmlDoc.getElementsByTagName("ID");
    	y=xmlDoc.getElementsByTagName("date");
    	z=xmlDoc.getElementsByTagName("retdate");
    	p=xmlDoc.getElementsByTagName("SID");
        for (i=0;i<x.length;i++)
          {
          txt=txt + x[i].childNodes[0].nodeValue +"<br />";
    	  txt +=y[i].childNodes[0].nodeValue + "<br />";
    	  txt +=z[i].childNodes[0].nodeValue + "<br />";
    	  txt +=p[i].childNodes[0].nodeValue + "<br /><br />";
          }
        document.getElementById("myDiv").innerHTML=txt;
        document.getElementById("push").style.display = 'none';
        }
      }
    xmlhttp.open("GET","loans.xml",true);
    xmlhttp.send('');
    }
    </script>
    </head>
    
    <body>
    <div id="myDiv"></div>
    <button type="button" id="push" onclick="loadXMLDoc()">Decode xml File</button>
    </body>
    </html>
    It's a little clunky but I think you can see whats going on. As for me I think I'll start to relearn xml and update my code.

    I am sorry, but how do i go about running & reading the code. I am currently using netbeans. I am really very lost as I just learn xml like 2 days back and I am task to do all this. Do i say my loan.xml in the netbeans? What about those you gave me? I am really sorry for all the question. Hope you can guide me along.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,729
    Thanks
    6
    Thanked 1,016 Times in 989 Posts
    Sorry, the last post above was in the moderation queue and I only noticed it just now. Hope it’s not too late yet.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •