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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Extracting data using javascript...

    Hello!

    I want to extract data from an xml-sheet using javascript. I have a number of textfields in which I insert some of the data I need. So far so good.

    I want to extract data from certain nodes and insert that data into a list. One of the problems is that it has to be done dynamically, it is not to be done a fixed number of times, some times it has to be done one time, other times it has to be done fourteen times.

    My xml-sheet looks like this:
    <?xml version="1.0" encoding="ISO8859-1" ?>
    <personal>
    <person>
    <anstnr>1</anstnr>
    <enamn>Eriksson</enamn>
    <fnamn>Rikard</fnamn>
    <sign>rier</sign>
    <persnr>780101</persnr>
    <skiftlag>1</skiftlag>
    <disponibel>Ja</disponibel>
    <merit>
    <meritid>4</meritid>
    <kurskod>B1</kurskod>
    <exdag>2001-12-01</exdag>
    </merit>
    </person>
    </personal>

    I want to extract meritid, kurskod and exdag and place them in an array so that I can extract them by looping through the array. I´m planning to use javascript to do the looping part.

    I appreciate any suggestions or help :-)

    Many thanks in advance

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    OK, to help you answer this we have to explore how to treat XML in IE & Mozilla / Netscape.

    In Netscape / Mozilla, you can access the DOM directly from the XML document with a namespaced XHTML script element.

    <personal>
    <!-- ... -->
    <script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
    // JavaScript goes here
    ]]></script>
    </personal>

    It's best in this context to enclose all your actions in functions; don't call them before onload if you can help it. (That's why I place the script here at the end of the document -- a practice which is usually avoided like the plague.)

    In IE, the best shot you'll have is placing the XML document as an XML island:

    <html>
    <!-- ... -->
    <body>
    <!-- ... -->
    <xml id="xmlDoc"><!-- xml document fragment goes here --></xml>
    </body>
    </html>
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    forgot to say IE

    Hello Alex!

    I forgot to mention that I will only use IE, sorry.

    I´ll try to use xml islands.

    Thanks for your advice :-)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An alternative to xml dataislands is to load the xml document as an activeX object, e.g.

    var xml_doc = new ActiveXObject("Microsoft.XMLDOM")
    xml_doc.async = false
    xml_doc.load("somefile.xml")

    patrick

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a post that may help you. Read the part about the XML ticker instead of the Javascript one...

    http://www.codingforums.com/showthre...&threadid=6777


  •  

    Posting Permissions

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