oleber
asked on
Processing the HTML DOM in Javascript with XPath
I need to do some test in my code, so I'm interested in processing the HTML DOM in a IFrame being tested. Some complex XPath can allow me to find elements ease.
So lets see the questions.
Having a document, II need to use some XPath to find Elements in the HTML DOM.
How to do it?
So lets see the questions.
Having a document, II need to use some XPath to find Elements in the HTML DOM.
How to do it?
ASKER
My question is not how to write XPath, I know that.
The idea is to get my application in a Iframe. After, to be able of finding elements in the HTML DOM of that IFrame using XPath.
NOTE: The application and the Test pages are in the some domain.
Let me rephrase my questions:
How do I get the DOM of the Iframe?
How to find a element or a group of elements in the DOM using XPath.
The idea is to get my application in a Iframe. After, to be able of finding elements in the HTML DOM of that IFrame using XPath.
NOTE: The application and the Test pages are in the some domain.
Let me rephrase my questions:
How do I get the DOM of the Iframe?
How to find a element or a group of elements in the DOM using XPath.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have this code, the first 2 alerts appear.
The 3º doesn't appear.
What is wrong ???
<html>
<script>
function myTest(iframe) {
alert("Loaded: " + iframe );
var document = iframe.contentDocument;
if ( document == null || document == undefined ) {
document = iframe.contentWindow.document;
}
alert("Doc: " + document );
var elem = document.selectNodes("//body");
alert("XPath: " + elem );
}
</script>
<body bgcolor="#FF0000">
<iframe id="RSIFrame" name="RSIFrame" style="width:800px; height:600px; border: 3px" src="iframe.html" onLoad="myTest(this)">
</iframe>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.w3schools.com/XPath/default.asp