EXPennD
EXPennD

Reputation:

JQuery and XML parsing assistance

Here's the Scenerio, I'm creating a simple app for my friend's website where his users could add image w/ a caption. The problem is My Friend's Webhost don't allow him to use server side scripts and Database. He is just allowed to insert javascript and HTLM on the site.

So I think the solution would be doing it in XML instead of Database and Instead of Serverside sripts I would use Javascript (JQuery) to parse an XML. Now the next question is how would I code it? I just know basic JQuery and Javascript.

<!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>Jquery and XML</title>
</head>

<body>



<form id="form1" name="form1" method="post" action="jqueryxml">
  <p>First Name</p>
  <input type="text" name="FirstName" id="FirstName" />

  <br /><br />
  <p>Last Name</p>
  <input type="text" name="LastName" id="LastName" />

  <br />
  <br />
  <p>Sex</p>
  <input type="radio" name="sex" value="male" /> Male
<br />
<input type="radio" name="sex" value="female" /> Female
<br />
<br />
  <p>Image URL</p>
  <input type="text" name="ImgURL" id="LastName" />

  <br />
  <br />
<p>Description</p>
<textarea name="Desc" cols="40" rows="5"></textarea>
<br />
<br />
<input name="Submit" type="submit" value="Submit" />
</form>

</body>
</html>

I really need some good help out there!

Thank you!

Upvotes: 0

Views: 156

Answers (2)

climboid
climboid

Reputation: 6952

Not 100% sure but I think it would go something like this

xml code:

<contact-info>
<name>Jane Smith</name>
<company>AT&amp;T</company>
<phone>(212) 555-4567</phone>
</contact-info>

jquery ajax call:

$.ajax({
  url: "test.html",
  context: document.body,
  type: xml,
  success: function(xml){
    $(xml).find('contact-info').each(function(){
      var name = $(this).children('name');
      var company = $(this).children('company');
      var phone = $(this). children('phone');
    });
});

Upvotes: 0

Sorantis
Sorantis

Reputation: 14722

Here's an example parsing XML using jQuery

 $(request.responseXML).find("person").each(function() {

      var pointer= $(this);

      var data = {

          pointer.attr("FirstName"),
          pointer.attr("LastName"),
          pointer.attr("Sex"),
          pointer.attr("ImageURL"),
          pointer.attr("Description")

      };

  });

Upvotes: 1

Related Questions