Creating the XML Parser Object in Mozilla

Discussion in 'XML' started by saraaku, Feb 11, 2008.

  1. saraaku

    saraaku Guest

    Hello,

    I tried creating the xml parser object for mozilla, firefox but have
    had a hard time doing this. When I did this initially, it worked.
    But, when I tried it again, it did not. Does spaces in the formula
    affect it?

    Can someone please provide me the correct formula to create this
    object and how I can check if spaces are the reason why it does not
    work?

    Thanks
    saraaku, Feb 11, 2008
    #1
    1. Advertising

  2. > Can someone please provide me the correct formula to create this
    > object and how I can check if spaces are the reason why it does not
    > work?


    Is this what you are referring to?

    var parser = new DOMParser();
    var xml = parser.parseFromString("<myNode>some valid xml</
    myNode>","text/xml");

    Rob
    :)
    Robert Mark Bram, Feb 12, 2008
    #2
    1. Advertising

  3. saraaku wrote:

    > I tried creating the xml parser object for mozilla, firefox but have
    > had a hard time doing this. When I did this initially, it worked.
    > But, when I tried it again, it did not. Does spaces in the formula
    > affect it?
    >
    > Can someone please provide me the correct formula to create this
    > object and how I can check if spaces are the reason why it does not
    > work?


    It is not clear what you are talking about. Do you want to load XML from
    a URL? Then you have to possibilities
    1)
    var xmlDoc = document.implementation.createDocument('', 'dummy', null);
    xmlDoc.onload = function () {
    // handle document here
    }
    xmlDoc.load('file.xml')
    2)
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', 'file.xml', true);
    httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState === 4) {
    // handle httpRequest.responseXML here
    }
    }
    httpRequest.send(null);

    If you want to parse a string with XML then use
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(xmlString, 'application/xml');


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 12, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ZOCOR

    XML Parser VS HTML Parser

    ZOCOR, Oct 3, 2004, in forum: Java
    Replies:
    11
    Views:
    797
    Paul King
    Oct 5, 2004
  2. arne
    Replies:
    0
    Views:
    342
  3. Erik Wasser
    Replies:
    5
    Views:
    428
    Peter J. Holzer
    Mar 5, 2006
  4. Sean
    Replies:
    3
    Views:
    252
    robic0
    Oct 3, 2006
  5. Sean
    Replies:
    0
    Views:
    358
Loading...

Share This Page