www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to get started with JavaScript(jQuery) and XML

  1. #1
    Join Date
    Jan 2011
    Posts
    18

    Question How to get started with JavaScript(jQuery) and XML

    I'm new to XML, so I was wondering can someone help me to get started with it.
    Basically, I have a simple HTML document:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>XML TESTING</title>
    <link type="text/css" href="jquery-ui-1.8.9.custom.css" rel="Stylesheet" />	
    
    
    		<script type="text/javascript" src="jquery-1.4.4.min.js"></script> 
    
    		<script type="text/javascript" src="jquery-ui-1.8.9.custom.min.js"></script>
    
    		<script type="text/javascript" src="script.js"></script>
    
    </head>
    
    <body>
    	<p>TEXT</p>
    </body>
    </html>
    and I have a simple XML file:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
     <products>
     	
     	<product>
     	<name>Pioneer</name>
    	<price>1400din</price>
    	<info>Pioneer info</info>
    	</product>
    	
    	<product>
     	<name>Khan</name>
    	<price>5400din</price>
    	<info>Khan info</info>
    	</product>
    	
    	<product>
     	<name>Seme</name>
    	<price>3400din</price>
    	<info>Seme info</info>
    	</product>
    	
     	
     	
     </products>
    I just want to connect my XML with my HTML with JavaScript (or preferably jQuery) and change the inner text of paragraph to info value of the first product. In the end, my HTML document should have a single paragraph with a text "Pioneer info" so how do I that?
    Do I have to have a server to do that (I have WAMP installed on my PC so that won't be problem) or not?
    Basically I just need the JS or jQuery script that can connect to XML and replace contents of a paragraph with a content from a specific element from my XML.

  2. #2
    Join Date
    Jan 2011
    Posts
    20
    I suggest that you start here:

    http://www.w3schools.com/

    Great website with loads of great tutorials

  3. #3
    Join Date
    Jan 2011
    Posts
    18
    Been there, but it seems that my code won't work unless I upload XML and HTML to a remote server, is there a way to run my code somehow locally?

  4. #4
    Join Date
    Jan 2011
    Posts
    20
    Ok so you want to display info from an XML file using javascript?

    maybe this is what you are looking for:

    http://www.w3schools.com/XML/tryit.a...xml_parsertest

  5. #5
    Join Date
    Jan 2011
    Posts
    18
    That's about it, but it doesn't work locally.
    I've used this example as well:
    http://www.vagrantradio.com/2009/10/...-and-ajax.html
    but with no luck since I have to upload all my files on a actual remote server, so my question is can I somehow run this locally?
    I've tried using WAMP, but it doesn't work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles