Read entire xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunny

    Read entire xml file

    Hi,
    Can someone tell me how to get the content of entire xml file in
    Firefox?
    I am using this code to load the xml file.
    if (document.imple mentation && document.implem entation.create Document)
    {
    xmlDoc = document.implem entation.create Document("","", null);
    xmlDoc.async="f alse";
    var isLoaded = xmlDoc.load("al lcounties_3.xml ");
    if (isLoaded == true) {
    //alert(xmlDoc.do cumentElement.x ml);
    }
    }

    I tried xmlDoc.document Element.xml but it dont work.
    How can I read the entire xml file in a variable?
  • Martin Honnen

    #2
    Re: Read entire xml file

    Sunny wrote:
    I am using this code to load the xml file.
    if (document.imple mentation && document.implem entation.create Document)
    {
    xmlDoc = document.implem entation.create Document("","", null);
    xmlDoc.async="f alse";
    You should assign a boolean value not a string to the async property:
    xmlDoc.async = false;
    However that blocks the browser while loading the document so that is
    usually not a good idea. Consider to use asynchronous loading (async =
    true) in a browser environment.
    var isLoaded = xmlDoc.load("al lcounties_3.xml ");
    if (isLoaded == true) {
    //alert(xmlDoc.do cumentElement.x ml);
    }
    }
    >
    I tried xmlDoc.document Element.xml but it dont work.
    How can I read the entire xml file in a variable?
    Well xmlDoc is a variable containing the XML document as a DOM tree.
    If you only want a string then I am not sure why you use
    createDocument( ) and the load method, you could use XMLHttpRequest and
    simply access responseText.
    Or, if you think you need createDocument( ) and the load method, then you
    need to serialize the DOM tree e.g.
    var xml = new XMLSerializer() .serializeToStr ing(xmlDoc);

    --

    Martin Honnen

    Comment

    Working...