Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Microsoft.XMLDOM - Not sure what i'm missing

Posted on 2005-05-01
8
Medium Priority
?
216 Views
Last Modified: 2011-09-20
Im trying to interface with a XML page pervided by Mythic. Im not sure what i am missing.
The xml page is here - http://www.camelotherald.com/xml/servers.xml
Im just wanting a few attributes out of the <server> node: Name - Status - Population
Thank you for your help the code that i have is bellow

<table  border=0 cellpadding=0 cellspacing=0 ID="Table2" style="color: #707070;">
      <tr><td height=24px> </td></tr>
      <tr><td><b>Server</b></td><td><b>Status</b></td><td><b>Pop</b></td></tr>
      <script language=javascript>
            var x = new ActiveXObject("Microsoft.XMLDOM");
            x.async = "false";
            x.load("http://www.camelotherald.com/xml/servers.xml");
            for(var i = 0; i < x.documentElement.childNodes.length; i++)
            {
                  document.write("<tr><td width=80>" + x.documentElement.childNodes(i).attributes(0).text + "</td>");
                  document.write("<td width=50>" + x.documentElement.childNodes(i).childNodes(1).text + "</td>");
                  document.write("<td>" + x.documentElement.childNodes(i).childNodes(0).text + "</td></tr>");
            }
      </script>
</table>
0
Comment
Question by:ilaird
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13907322
I think it is because of the DTD decleration in that XML file.
when saved localy it still won't load until you remvoe the dtd decleration.

try loading it as text via xmlhttp
the use a regexp to remove the dtd decleration
and only the use loadXML to parse it.

SnowFlake
0
 
LVL 2

Author Comment

by:ilaird
ID: 13946373
ya i found that too. The porblem is that this xml file is a living doc. I need to get hte most up to date. Im not buying that a big company like mythic (the owner of the xml file) would post a malformed document. Is there a way to get around the declarains and still use the XMLDOM object?
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13948016
this one seems to work for me other then the fact that it gives out a warning
about accessing content from another domain.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<table  border=0 cellpadding=0 cellspacing=0 ID="Table2" style="color: #707070;">
     <tr><td height=24px> </td></tr>
     <tr><td><b>Server</b></td><td><b>Status</b></td><td><b>Pop</b></td></tr>
     <script language=javascript>
          var x = new ActiveXObject("Microsoft.XMLDOM");
          x.resolveExternals=false;
          x.async = false;
          x.load("http://www.camelotherald.com/xml/servers.xml");
         
          x.load("local.xml");
          alert(x.documentElement);
          var nodesList = x.documentElement.selectNodes("//server");
          alert(nodesList);
          for(var i = 0; i < nodesList.length; i++)
          {
               document.write("<tr><td width=80>" + nodesList.item(i).attributes(0).text + "</td>");
               document.write("<td width=50>" + nodesList.item(i).childNodes(1).text + "</td>");
               document.write("<td>" + nodesList.item(i).childNodes(0).text + "</td></tr>");
          }
     </script>
</table>
</body>
</html>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:ilaird
ID: 13949256
what is with the load local.xml?  

- im getting a first element of null then a error on page.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13951085
my bad,
I worked on it for a while, I added a local version of the XML
and had the first load in a comment.

then later on I came back to it , I added the resolveExternals=false;
removed the comment from the original load but forgot to remove the local load.

It worked and I thought that was it.

well It does not work yet, But I will keep trying.

SnowFlake
0
 
LVL 15

Accepted Solution

by:
SnowFlake earned 400 total points
ID: 13951106
And a short search that was:

add

x.validateOnParse = false;

right after
x.resolveExternals=false;

It new realy works for me with the original XML.

Please let me know if it works for you as well.
0
 
LVL 2

Author Comment

by:ilaird
ID: 13951829
Alright!

that was the kicker! xvalidateOnParse = false;
Makes sence. For everyone that was looking for the same info here is the finishe chunk of code
Thankx snow! :D

<table  border=0 cellpadding=0 cellspacing=0 ID="Table2" style="color: #707070;">
<tr><td height=24px> </td></tr>
<tr><td><b>Server</b></td><td><b>Status</b></td><td><b>Pop</b></td></tr>
<script language=javascript>
      var x = new ActiveXObject("Microsoft.XMLDOM");
      x.resolveExternals=false;
      x.validateOnParse = false;
      x.async = false;
      x.load("http://www.camelotherald.com/xml/servers.xml");
                                                    
      var nodesList = x.documentElement.selectNodes("//server");
      for(var i = 0; i < nodesList.length; i++)
      {
            document.write("<tr><td width=80>" + nodesList.item(i).attributes(0).text + "</td>");
            document.write("<td width=50>" + nodesList.item(i).childNodes(1).text + "</td>");
            document.write("<td>" + nodesList.item(i).childNodes(0).text + "</td></tr>");
      }
</script>
</table>
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13951981
your welcome :)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question