File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes DOM sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "DOM sorting" Watch "DOM sorting" New topic
Author

DOM sorting

Bob Green
Ranch Hand

Joined: Feb 29, 2004
Posts: 93
I have the following xml file and need to be able to retrieve some data based on user input, how to go about it if I need to implement with javascript?
For instance, if the user wants to retrieve all the documents that belong to the ENGLISH department.

TIA,

<documents>
<document>
<id>A1</id>
<docType>DOC</docType>
<department>ENGLICH</department>
</document>
<document>
<id>T1</id>
<docType>DOC</docType>
<department>BUSINESS</department>
</document>
<document>
<document>
<id>P1</id>
<docType>DOC</docType>
<department>ECONOMY</department>
</document>
<document>
<id>A2</id>
<docType>PDF</docType>
<department>ENGLISH</department>
</document>
<document>
<id>A2</id>
<docType>PDF</docType>
<department>BUSINESS</department>
</document>
<document>
<id>A2</id>
<docType>PDF</docType>
<department>ECONOMY</department>
</document>
<document>
<id>A3</id>
<docType>TXT</docType>
<department>ENGLISH</department>
</document>
</documents>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
JavaScript does not have file I/O capabilities, so how would it get at the contents of this file?


Ping & DNS - updated with new look and Ping home screen widget
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by Ulf Dittmer:
JavaScript does not have file I/O capabilities, so how would it get at the contents of this file?


Ulf you living under a stone? XMLHttpRequest?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Only way to do it is going to be a for loop that looks at the node text.

Eric
Bob Green
Ranch Hand

Joined: Feb 29, 2004
Posts: 93
Thank you for all your inputs. I am thinking about using the Document Object Model after parsing the xml to a DOM object.... Am I on the right track?

TIA
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
Originally posted by Eric Pascarello:
Ulf you living under a stone? XMLHttpRequest?


XHR does files now? I thought it was some kind of HTTP thingy.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by Bob Lou:
Thank you for all your inputs. I am thinking about using the Document Object Model after parsing the xml to a DOM object.... Am I on the right track?

TIA


It is what I said you were going to have to do is use it ot loop through the values

something like
xmlDoc.getElementsByTagName("document")[0].childNodes[2].nodeValue;
or
xmlDoc.getElementsByTagName("document")[0].getElementsByTagName("department")[0].nodeValue;

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by Ulf Dittmer:


XHR does files now? I thought it was some kind of HTTP thingy.


I am just going to act like you are a on some sort of medication and do not have a clear mind! Yes you can grab XML, html, text, jsp, asp, .aspx, etc.

Eric
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
Originally posted by Eric Pascarello:
I am just going to act like you are a on some sort of medication and do not have a clear mind!


That's generally a good assumption. Can't seem to get rid of that ringing in my ears anyways, so I might as well take another dose right now...
[ June 07, 2007: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOM sorting
 
Similar Threads
trouble passing info from servlet to jsp
How to enhance this code further ??
XHTML documents vs. XHTML syntax in HTML documents
converting html to pdf
xPath questions