Results 1 to 12 of 12

Thread: Filtering a xml document using JavaScript

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69

    Filtering a xml document using JavaScript

    <script language="javascript">
    // Load XML
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load("dagskra.xml")

    // Load the XSL
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load("dagskra3.xsl")

    // Transform
    document.write(xml.transformNode(xsl))
    </script>

    This script takes a xml file and display using the xsl stylesheet. In a similar code in asp you can filter the xml file before it is displayed. Can that be done in JavaScript?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Im confused. So is the problem that your code doesnt work? You are showing javascript code. Although you show it client side which is really kind of useless since IE 5+ already does what that code does and it wont work in netscape anyway
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69
    I need to filter the xml before displaying it. I can do it in the xsl file, but I would like to do it in the htm file.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    As far as I know, IE already filters/styles the xml BEFORE displaying if you add the stylesheet reference to the xml document.

    You also did not answer my question. What is the problem with the javascript you posted?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69
    There is nothing wrong with the code. Yes IE5 does filter/style the xml document according to the xsl file. But in this case I would rather let the htm file filter the xml file instead of the xsl file.

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Ok well then if there is nothing wrong with your code, then you have already answered your question. Either you are not telling us what the problem is, or I have completely missed the point of what you are trying to ask.

    Here is how I read you:

    You posted JAVASCRIPT that works and asked for JAVASCRIPT on how to do it.

    That is how your first post reads. So what exactly is the problem you are having?

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69
    CAN JavaScript FILTER an xml document?

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Ok. Yes and No. The javascript itself does not, but the MSXML parser object you set a reference to will and should output the final rendered xml/html document.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69
    Do you know the code for it?

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    the code you already posted should work. Have you tried it?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Akureyri, Iceland
    Posts
    69
    It has always worked with the filter attributes in the xsl file.
    But I need to add a JavaScript function that lets the MSXML parser object filter the xml with for example date='20010521'

  12. #12
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Ohhhh ok now I fully understand. Hmm Im not to sure how to go about doing it in javascript. Ill see what I can come up with.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

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



Click Here to Expand Forum to Full Width