• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DOM sorting

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript does not have file I/O capabilities, so how would it get at the contents of this file?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only way to do it is going to be a for loop that looks at the node text.

Eric
 
Bob Green
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic