• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using XPath to do an XML lookup

 
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
~Ok so this may seem like deja vu to some, but i need to find a way to use XPath to do an XML Look up. My server can only do Javascritp (duh) or PHP.

~I want to be able to click on a link in an HTML or PHP page and get two dialogues:
1. the Download window
2. the Information Window

~The Information window is my problem. I need to have just one HTML (or PHP0 page for the window and just one XML page. This XML page would have all the information on the products.

~The Information window needs to access the XML page, get the correct entry, load it and display it.

~Does anyone have any idea how to do this, or where I could learn how to do this?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't matter what language you use on the server-side as long as it can spit out XML. I'm using jQuery for doing something very similar on the client-side.

Basically, I have the following jQuery code:


The prog.xml file contains XML similar as the following one:


You can see that jQuery lets you specify an XPath expression (prog/entry) for selecting DOM nodes in the XML retrieved from the server. From there, everything else is basic stuff.

Hope this helps.
 
ian bert
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok ill try this
 
ian bert
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think it will work
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not ?
Can you share your code ?
 
ian bert
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the parts of the code the poster thing wont allow is seperated by a space

Script.js
var xmlDoc;
products.function(id, name, file_size, summary)
{
this.id=id;
this.name=name;
this.file_size=file_size;
this.summary=summary;
}
function loadXML(){
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("product_info.xml");
var id=attrs.getNamedItem("id").value;
var name=attrs.getNamedItem("name").value;
var version=parseFloat(attrs.getNamedItem("file_size").value)
var file_size=attrs.getNamedItem("summary").value;
getmessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("product_info.xml");
var id=attrs.getNamedItem("id").value;
var name=attrs.getNamedItem("name").value;
var version=parseFloat(attrs.getNamedItem("file_size").value)
var file_size=attrs.getNamedItem("summary").value;
xmlDoc.o nload=getmessage;
}
else
{
alert('Your browser cannot handle this script');
}
}
// Actual message maker
function getmessage()
{
document.getElementById("name").innerHTML=xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
document.getElementById("file_size").innerHTML=xmlDoc.getElementsByTagName("file_size")[0].childNodes[0].nodeValue;
document.getElementById("summary").innerHTML=xmlDoc.getElementsByTagName("summary")[0].childNodes[0].nodeValue;
document.getElementById("version").innerHTML=xmlDoc.getElementsByTagName("version")[0].childNodes[0].nodeValue;
}

function dio(){
window.open("dio.html");

}

Programs.html
<!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>
<link rel="SHORTCUT ICON" href="images/logo_orig/bp.ico" />
<script src="script.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Bertolacci Productions~Programs</title>
</head>
<body bgcolor="#fffacd" text="#000000" link="FF4500">
<center>
<h1>Programs</h1>
</center>
<hr color="#CC9900" size=2 width="100%"/>
<center>
<a href="http://www.bertolacciproductions.com"><img src="images/buttons/home.bmp" alt="Home" border="none"/></a>
<a href="new.html"><img src="images/buttons/new.bmp" alt="New" border="none"/></a>
<a href="programs.html"><img src="images/buttons/programs.bmp" alt="Programs" border="none"/></a>
<a href="add-ins.html"><img src="images/buttons/add-ins.bmp" alt="Add-Ins" border="none"/></a>
<a href="box-sets.html"><img src="images/buttons/boxset.bmp" alt="Box Sets" border="none"/></a>
<a href="service.html"><img src="images/buttons/service.bmp" alt="Services" border="none"/></a>
<a href="about.html"><img src="images/buttons/about.bmp" alt="About" border="none"/></a>
<a href="code/codebook.html"><img src="images/buttons/code.bmp" alt="Code Cook Book" border="none"/></a>
</center>
<hr color="#CC9900" size=2 width="100%"/>
<center>
<table border="0">
<tr>
<td width="121">Programs</td>
<td width="121">Games</td>
<td width="121">Other</td>
</tr>
<tr>
<td width="121"></td>
<td width="121"><a o nclick="dio(001)" href="Downloads/programs/games/bustin'_blox.exe">Bustin' Blox</a></td>
<td width="121"></td>

<tr>
</table>
</center>
</body>
</html>

product_info.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<products>
<download id="001" name="Bustin' Blox" file_size"2 Mb" summary"Our version of Brick. Only One Level (Kinda Sucks)" version="1.0"/>
<download id="002" id="001" name="ASDF" file_size"ASDF" summary"ASDF" version="1.0"/>
</products>

dio.html
<!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>
<link rel="SHORTCUT ICON" href="images/logo_orig/info.ico" />
<script src="script.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Product Info</title>
</head>
<body o nload="loadXML(id)" bgcolor="#fffacd" text="#000000" link="FF4500">
<center>
<h1>Product Information</h1>
</center>
<p>
<b><u>File Name: </u></b><span id="name"></span><br />
<b><u>File Size: </u></b><span id="file_size"></span><br />
<b><u>File Summary: </u></b><span id="summary"></span><br />
<b><u>File Version: </u></b><span id="version"></span><br />
</p>
</body>
</html>
 
ian bert
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello?
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you explain which problems you're experiencing?

Run your code in Firefox using the Firebug extension and you'll see a couple errors
[ September 08, 2007: Message edited by: Valentin Crettaz ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ian bert:
[QB My server can only do Javascritp (duh) ....[/QB]



Server and Javascript ?? Am I missing something.
 
ian bert
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No you arent
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic