All source code in Java/ Javascript Ask a Java/ Javascript Pro Discussion Forum Categories All jobs in Java/ Javascript
AJAX,XML,with,applications,allows,xpath,expre
   Code/Articles � |  Newest/Best � |  Community � |  Jobs � |  Other � |  Goto � | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Java/ Javascript Stats

 Code: 484,040. lines
 Jobs: 194. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for Java/ Javascript.
Click here to see a screenshot of this code!My First Struts2 Application
By nagesh borate on 2/7

(Screen Shot)

Click here to see a screenshot of this code!Peg solitaire
By Mario Segura on 2/4

(Screen Shot)

Simple TicTacToe
By Atishay Jain on 2/4


moon info
By marcojetson on 2/3


Click here to see a screenshot of this code!SLOT MACHINE
By Husain Limdiyawala on 2/1

(Screen Shot)

Click here to see a screenshot of this code!NLabs' Password Generator
By nagesh borate on 2/1

(Screen Shot)

DragAndDrop
By Masood Fallahpoor on 1/30


Click here to see a screenshot of this code!HTML Learning By Azhar Khan
By Azhar Khan Website Designer on 1/30

(Screen Shot)

Beautiful Graphics applet
By Tejas Jayantilal Gandhi on 1/28


Click here to see a screenshot of this code!The Picture Grapher 2010 beta
By ROD LEWIS on 1/26

(Screen Shot)

xo
By ahmed wagih on 1/26


Click here to see a screenshot of this code!Mobile Tracer by Azhar Khan
By Azhar Khan Website Designer on 1/26

(Screen Shot)

Click here to see a screenshot of this code!tic tac toe AI with multiple difficulties
By Michael Nipper on 1/23

(Screen Shot)

Click here to see a screenshot of this code!A Basic tutorial on JavaScript and HTML
By Ronald Holland on 10/27

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

javascript cross browser xpath function

Print
Email
 
VB icon
Submitted on: 6/10/2006 4:49:35 AM
By: Charles Toepfer 
Level: Intermediate
User Rating: Unrated
Compatibility:JavaScript

Users have accessed this code 54624 times.
 
(About the author)
 
     For use with AJAX web applications, allows xpath expressions on XML data objects.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: javascript cross browser xpath 
//     function
// Description:For use with AJAX web app
//     lications, allows xpath expressions on X
//     ML data objects.
// By: Charles Toepfer
//
// Inputs:XML DOM element, xPath string
//
// Returns:resulting XML DOM
//
// Assumes:Here are some sample xpath st
//     atements:
Select nodes where the attribute name is Bob Mickles: //*[@name='Bob Mickles']
Select nodes that contain bob in the text: //nodes/node/*[contains(.,'Bob')];
or .. //nodes/node/node[contains(.,'Bob')];
Simple path select: //nodes/node
Select nodes that contain bob, retrieve child 'node': //nodes/node[node='bob']/node
Select nodes that nodes that contain bob in nodeA and mickles in nodeB: //nodes/node[nodeA='bob' and nodeB='mickles']
Select nodes where the name node is unique: //nodes/node[not(name = preceding-sibling::node/name)]
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=5314&lngWId=2//for details.//**************************************
//     

function xPath(oNodes, sXPath)


    {
    /*
    xPath function by Charles Toepfer: toepfer_c@hotmail.com 
    use: 'resulting xml dom' = xPath('xml dom object', 'xpath string');
    */
    if(oNodes)


        {
        if(window.XMLHttpRequest)


            { 
            try 


                {
                var oXpe = new XPathEvaluator();
                var oNsResolver = oXpe.createNSResolver(oNodes.ownerDocument == null ? oNodes.documentElement : oNodes.ownerDocument.documentElement);
                var oResult = oXpe.evaluate(sXPath, oNodes, oNsResolver, 0, null);
                var aFound = [];
                var oRes;
                while (oRes = oResult.iterateNext())


                    {
                    aFound.push(oRes);
                }

return aFound; }
catch (e) { alert(e.description); }
}
else { try { oNodes.setProperty ("SelectionLanguage", "XPath") var oSelectedNode = oNodes.documentElement.selectNodes(sXPath); return oSelectedNode; }
catch (e) { alert(e.description); }
}
}
}


Other 6 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | Java/ Javascript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright� 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Exhedra solutions has no affiliation with Sun Microsystems, Inc.. Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.