• 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

How do I detect text wiithin the spantags

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following HTML
<span class="aaa">row is locked</span>

I want to extract that from the response. the following code will print out the response content but will not print out anything between the span tags.

private void printElementsWithAttributes(WebResponse webresponse) throws Exception
{
String [] elementNames = webresponse.getElementNames();
for(int index = 0; index < elementNames.length; index++)
{
HTMLElement [] htmlelements = webresponse.getElementsWithName(elementNames[index]);
for(int jindex = 0; jindex < htmlelements.length; jindex++)
{
System.out.print(htmlelements[jindex].getName()+" | ");
System.out.print(htmlelements[jindex].getTagName()+" | ");
System.out.print(htmlelements[jindex].getText());
}

}
}

Thanks for any help

Tony
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LOL going round in circles on this. I have changed my code and am able to pick up most of the html ecept the text bit.

Given <span class="x10">Data locked</span>

The following code will pick up

Node Name span

Nodes in the Map 1

node name class

node value xq

private void printDocumentModel(WebResponse webresponse) throws Exception
{
Node node = webresponse.getDOM();
printNodeLists(node);

}

private void printNodeLists(Node node) throws Exception
{
NodeList nl = node.getChildNodes();
for(int index= 0; index < nl.getLength(); index++)
{
if(nl.item(index).getNodeName().equals("span"))
{
System.out.println("Node Name "+nl.item(index).getNodeName());
NamedNodeMap nnm = nl.item(index).getAttributes();
System.out.println("Nodes in the Map "+nnm.getLength());
Node childnode = nnm.item(0);
System.out.println(" node name "+childnode.getNodeName());
System.out.println(" node value "+childnode.getNodeValue());

}
printNodeLists(nl.item(index));
}

}

But for the I have no idae how to pick up the text Data locked. There is no method that says right you have the tag here is the value between the tags.

Thanks for any help

Tony
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to get the "child nodes" of the span node, which are "text" nodes, and append their "node value" together.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks got it working

Tony
reply
    Bookmark Topic Watch Topic
  • New Topic