Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2012, 10:41 AM   PM User | #1
zhennn
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
zhennn is an unknown quantity at this point
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.
zhennn is offline   Reply With Quote
Old 09-14-2012, 05:26 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
Quote:
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.
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
zhennn (09-15-2012)
Old 09-15-2012, 09:16 AM   PM User | #3
zhennn
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
zhennn is an unknown quantity at this point
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.
zhennn is offline   Reply With Quote
Old 09-20-2012, 06:03 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Sorry, the last post above was in the moderation queue and I only noticed it just now. Hope it’s not too late yet.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Tags
xml; remove; tag

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:00 AM.


Advertisement
Log in to turn off these ads.