Paul Clapham wrote:So your code found an Element, and you know what the toString() value of that Element is. Apparently that doesn't agree with what you expected to see, although you haven't told us what that was. But why are you concerned with what toString() returns? You have the Element, carry on and use it.
Paul Clapham wrote:So your code found an Element, and you know what the toString() value of that Element is. Apparently that doesn't agree with what you expected to see, although you haven't told us what that was. But why are you concerned with what toString() returns? You have the Element, carry on and use it.
Paul Clapham wrote:I have no idea what your last two posts mean. And in particular I don't understand what this "problem" is. You have code which was looking for a certain Element, and it found an Element. So what's the problem? Do you think it found the wrong Element? Because you haven't produced anything which suggests that.
Paul Clapham wrote:You mean the toString() value of that Element contains the string "null". I'm still not seeing why that is a problem. In fact I'm not seeing why the toString() value of the Element has anything to do with your requirements at all.
Rahul Divedi wrote:The value of 'found' is null.
For this program I'm getting the output [div:null].
g tsuji wrote:@Rahul Divedi
I refer only to the first post. From the code fragment, I can only conclude that the logic within the code is quite disjoint: one block does not follow quite naturally the other... The use of dom is quite lost...
g tsuji wrote:
g tsuji wrote:T
NodeList nodes=(NodeList)xPath.evaluate(sxp,doc,XPathConstants.NODESET);
[/code]
... and the sxp is in the line#1 of that block, I just isolated it for clarity.
[code]
String sxp="/xhtml:html/xhtml:body//xhtml:div[@id='id12']";
[/code]
g tsuji wrote:T
NodeList nodes=(NodeList)xPath.evaluate(sxp,doc,XPathConstants.NODESET);
[/code]
... and the sxp is in the line#1 of that block, I just isolated it for clarity.
[code]
String sxp="/xhtml:html/xhtml:body//xhtml:div[@id='id12']";
[/code]
g tsuji wrote:Thanks for the response. Sorry, that line should be read like this (and that you'd been aware, and that I just typing the code in real time without testing
Paul Clapham wrote:Yes, your XPath is wrong. It's missing a closing quote after the attribute value. But I'm surprised you didn't get an exception thrown when you ran that code?
Paul Clapham wrote:Yes, your XPath is wrong. It's missing a closing quote after the attribute value. But I'm surprised you didn't get an exception thrown when you ran that code?
Rahul Divedi wrote:I have tried to print the value of 'found' and its printing '[div:null]'. So is it because of wrong XPath?
Paul Clapham wrote:
Rahul Divedi wrote:I have tried to print the value of 'found' and its printing '[div:null]'. So is it because of wrong XPath?
No, it's more likely to be because of the correct XPath. That string suggests to me that your XPath has found a <div> element, which is what you asked it to look for. And of course the "value" of that <div> element, because Element objects always have null for their value. I believe William Brogden already directed you to the API documentation which tells you that the "value" is null. Which of course is irrelevant because you aren't interested in the "value" of the element anyway.
<div id="taquestion0b12" class="block" style="display:block">1><span style="color: #000000;"> SQL Stands for ?</span>
</div>
Element found = doc.getElementById("id12");
NodeList nodes=(NodeList)xPath.evaluate(sxp,doc,XPathConstants.NODESET);
for (int i=0; i<nodes.getLength(); i++) {
Element elem=(Element)nodes.item(i);
//each one is the searched div element with id attribute id12
elem.setIdAttribute("id", true);
Element found = doc.getElementById("id12");
// System.out.println("ELement found is:"+found);
Element script2 = doc.createElement("script");
script2.setAttribute("src", "cal.js");
script2.setAttribute("type","text/javascript");
script2.setAttribute("xml:space","preserve");
found.appendChild(script2);
}
(my own) Furthermore, what is setIdAttribute() method? never heard of it.
g tsuji wrote:You have to establish solidly the correctness of the xhtml first. I have looked at it and then no, it can't be correct! already at that level and any work on it is vain and misleading.
[4.2] Same problem for your getElementsByTagName("head") section. You again have to use getElementsByNameNS() as shown in my previous posts. Again, the createElement() the same error, you've to use createElementNS() variant.
I just noticed that it is adding to that <div> tag only but not just after the opening rather just before the corresponding closing </div> tag.
...that as I need to keep only one Javascript cal.js after that div tag and have to remove other two common.js and ligot.js, so will it be better or easier to modify the src of any of them and then to remove the spare one or this approach of adding cal.js and then removing other two is better?
Where does a nanny get ground to air missles? Protect this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|