Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Question not work xml parsing with js

    i don't see any result in my script execute

    i had this link at Source code
    Code:
    <?xml version="1.0" ?>
    <Catalog>
    	<Product Type="Book" SupplierId="5">
    		<ProductId>B10</ProductId>
    		<ProductName>Introduction to XML </ProductName>
    		<ListPrice>$50.00</ListPrice>
    	</Product>
    	<Product Type="CD" SupplierId="5">
    		<ProductId>C100</ProductId>
    		<ProductName>JavaScript Ebook </ProductName>
    		<ListPrice>$70.00</ListPrice>
    	</Product>
    </Catalog>
    And my xml parsing from javascript link is Source code
    Code:
    <html>
    <head>
    <title>Parsing XML from Javascript</title>
    <script type="text/javascript" src="#"></script>
    </head>
    <body>
    <script language="javascript" type="text/javascript" >
    	var xmlDoc = null ;
    	if ( document.implementation && document.implementation.createDocument ) {
    	xmlDoc = document.implementation.createDocument ( ' ' , ' ' , null );
    	} else {
    	xmlDoc = new ActiveXObject ( "Msxml12.DOMDocument.3.0" );
    	}
    	xmlDoc.asyn = false;
    	xmlDoc.load ( "http://localhost:70/xml/catalog.xml" ) 
    	for ( var i=0 ; i < xmlDoc.documentElement.childNodes.length ; i++ ) {
    	var node = xmlDoc.documentElement.childNodes[i];
    	if ( node.nodeType == 1 ) {
    	document.body.appendChild(document.createTextNode(node.nodeName));
    	document.body.appendChild(document.createElement("br"));
    	
    	for ( var j=0; j < node.attributes.length; j++ ) {
    	document.body.appendChild(document.createTextNode(
    		node.attributes[j].nodeName + " : " + 
    		node.attributes[j].nodeValue ));
    	document.body.appendChild(document.createElement("br"));
    	}
    	
    	for ( var j=0 ; j < node.childNodes.length ; j++ ) {
    	if( node.childNodes[j].nodeType != 1 ) continue;
    	document.body.appendChild(document.createTextNode (
    	   node.childNodes[j].nodeName + ": " +
    	   node.childNodes[j].firstChild.nodeValue ));
    	document.body.appendChild(document.createElement("br"));
    	}
    	
    	document.body.appendChild(document.createElement ("br"));
    	}
    }
    </script>
    </body>
    </html>
    How to fix this problem?
    i think just little wrong in my xml parsing script .
    Thanks

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    xmlDoc.async = false; // maybe that's it?

    Why aren't you using XMLHttpRequest? Why xmlDoc.load()? Are you getting any JS errors?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts
    xmlDoc.async = false; // maybe that's it?
    it right i wrong but
    anything don't show in my browser
    something is still wrong


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •