cavinfoo,
Have you tried updating msxml and using the code above?
-Jason
Main Topics
Browse All Topics1. I have a list of books arranged in XML format like below (stripped down)
2. User type in any words and the system will match the words to the book title and return the sorted result.
3. I am currently facing problem on using wildcard,
4. I am just using Javascript to loop the XML
On below is my part of my problematic script that doesn't work, I hope somebody can do correction on it
--------------------------
var myKeyword = "coral" //User enter keywords...
xmlDoc = new ActiveXObject("Microsoft.X
xmlDoc.async=false;
xmlDoc.load("books.xml");
var root = xmlDoc.documentElement;
var myNodes = root.selectSingleNode("/XM
var myXpath = "BOOK";
myXpath += "[contains(TITLE, '" + myKeyword + "')]" //put the keywords into the Xpath... problems....
var myNodes2 = myNodes.selectNodes(myXpat
for (i=0; i < myNodes2.length; i++)
{
//loop and display...
var myStr += myNodes2[i].selectSingleNo
}
myDiv.innerHTML = myStr;
--------------------------
<XML>
<BOOK>
<TITLE>A preliminary report on the diversity and feeding relationship of reef fishes of One Tree Island, Great Barrier Reef system,</TITLE>
</BOOK>
<BOOK>
<TITLE>A preliminary underwater survey of the extent of the coral reefs in and around some of the islands in the Gulf of Mannar,</TITLE>
</BOOK>
</XML>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: PraxisWebPosted on 2005-09-30 at 07:45:58ID: 14992756
There are a few problems I noted:
ocument.4. 0");
L");
h);
de("TITLE" ).text; rHTML = myStr;
1) Not sure where your script was executing from, but you need to make sure myDiv exists before setting its value.
2) contains was not supported as an XPATH function until MSXML 4.0
3) Your initial string declaration 'myStr' needs to be outside the loop.
<html>
<head>
<script language="JavaScript" type="text/javascript">
function onload(){
var myKeyword = "coral";
xmlDoc = new ActiveXObject("Msxml2.DOMD
xmlDoc.async=false;
xmlDoc.load("books.xml");
var root = xmlDoc.documentElement;
var myNodes = root.selectSingleNode("/XM
var myXpath = "BOOK";
myXpath += "[contains(TITLE, '" + myKeyword + "')]";
var myNodes2 = myNodes.selectNodes(myXpat
var myStr ='';
for (i=0; i < myNodes2.length; i++)
{
myStr+= myNodes2[i].selectSingleNo
}
document.all['myDiv'].inne
}
</script>
</head>
<body onload="onload()">
<div id="myDiv" name="myDiv"> </div>
</body>
</html>
If you get a "Cannot create automation object message" with the above code, then you will need to download msxml 4 (sp2)from microsoft.
www.microsoft.com/xml