1

what is the best way to change(without jquery) these html/javascript to work with ie9,

<html>
    <body>
        <div id="xmls">
            <xml id="myXml">
                <bookstore>
                    <book category="COOKING">
                        <title lang="en">Everyday Italian</title>
                        <author>Giada De Laurentiis</author>
                        <year>2005</year>
                        <price>30.00</price>
                    </book>
                </bookstore>
            </xml>
        </div>
        <!-- ...more html -->
    </body>
</html>

And read this html section with script

function readBooks() {
    var doc = null;
    try {
        doc = document.getElementById("myXml").XMLDocument.documentElement.childNodes.length;
        alert('msg =' + doc);
        //i need child nodes to iterate and show values,
    } catch (ex) {
        alert("problems to load xml" + doc);
        throw ex;
    }
}

these works fine with ie6,7,8.

but with with ie9 not.

the XMLDocument property is undefined,

thanks,

2
  • sorry, my xml is writed into html document Commented Dec 23, 2011 at 16:41
  • 2
    I think you forgot to mention what the concrete problem is. Have you tried it on IE9? Is it not working? How? Any error? Any unexpected outcome? Commented Dec 23, 2011 at 16:48

2 Answers 2

1

the following seemed fine in modern browsers

function readBooks() {
      var doc;
      try {
          doc = document.getElementById("myXml")
          alert('msg =' + doc.childNodes.length);
          for (var i = 0; i < doc.childNodes.length; i++) {
            if(doc.childNodes[i].tagName && doc.childNodes[i].tagName.toUpperCase() == "BOOKSTORE") {

                for (var j = 0; j < doc.childNodes[i].childNodes.length; j++) {
                    if (doc.childNodes[i].childNodes[j].tagName && doc.childNodes[i].childNodes[j].tagName.toUpperCase() == "BOOK") {
                        var book = doc.childNodes[i].childNodes[j];
                        alert(book.getAttribute("category"));
                        alert(getNodeValue(book.getElementsByTagName("title")[0]));
                        alert(getNodeValue(book.getElementsByTagName("author")[0]));
                        alert(getNodeValue(book.getElementsByTagName("year")[0]));
                        alert(getNodeValue(book.getElementsByTagName("price")[0]));
                    }
                }
            }
          }
      } catch (ex) {
          alert("problems to load xml" + doc);
          throw ex;
      }
  }

  function getNodeValue(node) {

      if (node.text)
          return node.text;
      return node.innerHTML;
  }
Sign up to request clarification or add additional context in comments.

Comments

1

i solve these problem with String to XML, XML to String

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.