parsing a xml file using javascript does not givethe required result -


i trying parse xml-file using java-script. actually, read many tutorials find out how parse data xml-file correctly, , found on right way. concerning loadxmldoc(dname) function, passed path of xml-file loadxmldoc function follows:

var dname = "d:\files\files\schriftsteller.xml"; function loadxmldoc(dname) 

but still parsing not give me desired result, want display name in following tag

<name>jane austin</name> 

but web browser not display it, using chrome. please, (1) let me know mistake is? (2)what extension parser file should saved under(.html/.js)

please find below xml-file , java-script file

xml file:

<?xml version="1.0" ?>   <schriftsteller>      <englischsprache>         <dichtung>         <fueller>        <name>jane austin</name>                <name>rex stout</name>                <name>dashiell hammett</name>            </fueller>     </dichtung> </englischsprache>   </schriftsteller> 

javascript file.html(parser):

    <html>     <head>     <meta content="text/html;charset=utf-8" http-equiv="content-type">     <meta content="utf-8" http-equiv="encoding">           <link rel="stylesheet" href="readxml.css" type="text/css">        <title>read first child</title>          <!-- <xml id="schriftsteller" src="d:\files\files\schriftsteller.xml"></xml> -->         <script language="javascript">           var dname = "d:\files\files\schriftsteller.xml";          function loadxmldoc(dname)               {                  var xmldoc;                  if (window.xmlhttprequest)                  {                   xmldoc=new window.xmlhttprequest();                   xmldoc.open("get",dname,false);                   xmldoc.send();                   return xmldoc.responsexml;                  }                  // ie 5 , ie 6                   else if (activexobject("microsoft.xmldom"))                   {                    xmldoc=new activexobject("microsoft.xmldom");                    xmldoc.async=false;                    xmldoc.load(dname);                    return xmldoc;                   }                     alert("error loading document!");                     return null;               }                function findwriter()                {                  var schriftstellerknoten, spracheknoten;                  var fuellerknoten, dichtungknoten, anzeige;                   myxml = document.all(dname).xmldocumentalert(dname);                   schriftstellerknoten = myxml.documentelement;                  spracheknoten = schriftstellerknoten.firstchild;                  dichtungknoten = spracheknoten.firstchild;                  fuellerknoten = dichtungknoten.firstchild;                  namenode = fuellerknoten.firstchild;                  anzeige = namenode.firstchild.nodevalue;                  document.write(anzeige);               }            </script>   </head>   <body onload="loadxmldoc(dname)">   <span id="blueback">read firstchild</span>   <div>   <form name="show">   <input type=text name="me">   <input type="button" value="display writer"       onclick="findwriter()">   </form>   </div>  </body> 

first xml-document has well-formed.

so every tag open add tag close (like name-tag). closing tag has same opening, except / in beginning

also have watch case (well-formed xml case-sensitive). tag

<englischsprache> different <englischsprache>

try this:

<?xml version="1.0"?> <schriftsteller>   <englischsprache>     <dichtung>        <fueller>         <name>jane austin</name>         <name>rex stout</name>         <name>dashiell hammett</name>           </fueller>     </dichtung>    </englischsprache> </schriftsteller> 

then in js-file, maybe should try calling function loadxmldoc.

looks you're defining it.

try this:

<body onload="loadxmldoc(dname)"> 

better now?


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -