DOM query selected path and show as xml


 
Thread Tools Search this Thread
Top Forums Programming DOM query selected path and show as xml
# 1  
Old 11-17-2009
DOM query selected path and show as xml

First, I am sorry if this question not this room scope,

I have a XML file :

file: book.xml

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book category="COOKING">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

</bookstore>

I using this script If I want to show output of my script as xml file:
Code:
<html>
<body>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

xml=loadXMLDoc("books.xml");
document.write("<xmp>" + xml.xml + "</xmp>"); 

</script>

</body>
</html>

Now, I want to select specific path of XML node. The output that I want is like:
Code:
<bookstore>

<book category="COOKING">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
</bookstore>

and this is my script:

Code:
<html>
<body>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

xml=loadXMLDoc("books.xml");
path="/*/*[@*='COOKING']/*"
var nodes=xml.selectNodes(path);
document.write("<xmp>" + nodes.xml + "</xmp>"); 

</script>

</body>
</html>

Unfortunatelly, the script totally error. I dont know how to fix this. Smilie

Could you somebody please tell me how to print output only selected path criteria as xml?

Your answer really appreciated,

Thanks,
Denny
# 2  
Old 11-18-2009
I had to try the code myself to figure out what 'the script totally error' means. In fact it doesn't totally error, it loads the document fine, but displays nothing because, for one thing, an xmdocument has no "xml" member; and for another thing, you can't just print objects and expect to get xml. To see what members a Document actually has, look here.

---------- Post updated at 05:42 PM ---------- Previous update was at 05:31 PM ----------

You may also be interested in the XMLSerializer object.
# 3  
Old 11-23-2009
well, frankly, I only want to show output of my filtered xml file, like this, as xml :
Code:
<bookstore>

<book category="COOKING">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
</bookstore>

I will looking for example about XMLSerializer, maybe will help me.
Thanks Corona!
# 4  
Old 11-23-2009
I know; unfortunately that doesn't seem to be the simplest thing to do. The xmlhttprequest object is excellent at parsing xml into objects but can't do the reverse, which would seem to be the serializer's job.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shortest path for each query from a csv file

Hi all, I have this file __DATA__ child, Parent, probability, M7, Q, P, M7, M28, E, M28, M6, E, M6, Q, Pl, & several hundred lines..... Legends: P(= Probable) > Pl(=Plausible) > E(=Equivocal). What I want is for each child I want to trace it... (5 Replies)
Discussion started by: rushadrena
5 Replies

2. Shell Programming and Scripting

How do I get an ls -l to not show the full directory path?

Hey I'm new to the forums here, and I'm seeking help for this script that I'm writing. When I do ls -l of a directory it shows the full pathname for files in it. For example, if the directory is /internet/post/forum/ and the file is topic, it currently shows internet/post/forum/topic. What's the... (3 Replies)
Discussion started by: unity04
3 Replies

3. UNIX for Advanced & Expert Users

Perl XML::DOM: How to test if element exists?

Hi, I'm trying to write a script for some xml file handling, but I'm not getting too far with it. I've got the following xml content <?xml version="1.0" encoding="UTF-8"?> <Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <Operation name="OPER1"> <Action name="ACTION1">... (2 Replies)
Discussion started by: Juha
2 Replies

4. AIX

Perl Module (XML:DOM) dependency

Hi All, I am facing dependency on AIX :confused:.I am trying to run an script which requires PERL MODULE (XML::DOM) to be installed. Please find the attached file which shows the error i am getting (cant locate XML/DOM.pm in @INC). Please let me know how to install PERL MODULE (XML::DOM) ... (3 Replies)
Discussion started by: srivatsa86
3 Replies

5. Solaris

Non-Root mode ... luxadm to show path(s) for Disks

Hi Gurus out there... I am pondering over a situation where I have non-root access (user account), where I am trying to determine paths (including multipaths) on a host. "luxadm display" seems very appropriate, but requires root access. Is there anyway I can get the FC path information? ... (1 Reply)
Discussion started by: verisund
1 Replies

6. UNIX for Dummies Questions & Answers

how to use find commnad to show only path of the result

Hello all say i like to find files i do : find . -name "*.txt" but if i like to find ( and print out ) only the path's where the files are ( the *.txt files ) what can i add to the find command ? (1 Reply)
Discussion started by: umen
1 Replies

7. UNIX for Dummies Questions & Answers

Show path name

Hello I'm new to this forum. So please spare me! I'm using SCO UnixWare 7.1.4 and created a few accounts. So far so good. When I login I see: $. But here I want to see (for example), /home 25$ So I want to see the pathname where I am without each time typing pwd (2 Replies)
Discussion started by: p.vvugt
2 Replies

8. Shell Programming and Scripting

PS1 to show relitive path

Hi I am trying to format my prompt in a KSH to show the relative path currently it is PS1='$PWD >' /home/users/dir/dir/dir > I want to display it as /home/users/.../.../dir > :rolleyes: (2 Replies)
Discussion started by: truma1
2 Replies

9. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

10. Shell Programming and Scripting

How would I make a find command NOT show the path of a file?

When I do find . -name "*.txt" -size +0 -exec ls {} \; I get something like ./lpi_stdout.txt ./lpi_stderr.txt What would I need to do or pipe it into to strip off those first two characters so I just get lpi_stdout.txt lpi_stderr.txt ? Thanks for the help! (1 Reply)
Discussion started by: LordJezo
1 Replies
Login or Register to Ask a Question