473,414 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

path of an html node

i have an html document as follows

<html>
<body>
<h1>world</h1>
<br>
List
</body>
</html>

i want the path of each node of its dom tree representation

i wrote a code using htmlparser library

import org.htmlparser.Parser;
import org.htmlparser.Node;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.NodeIterator;
import org.htmlparser.util.ParserException;

public class ParserMain
{

public static void main(String[] args)throws ParserException
{
String str=null, stri=null;
Parser parser = new Parser ("file:///E:/project/d2.html");
NodeList list = parser.parse (null);

Node[] node = new Node[500];
int j=0;
Node rootnode = list.elementAt (0);
str=rootnode.getText();
System.out.println("root::"+str);

NodeList sublist = rootnode.getChildren ();

System.out.println("size is"+sublist.size());

NodeIterator i = sublist.elements();
while(i.hasMoreNodes())
{
j++;
node [j]= i.nextNode();
str=node[j].getText();
System.out.println("nodes are::"+str);
}

}
}

i'm not getting the name of every nodes.. i read that '\n' is also considered an element in the Nodelist. but i cant resolve it..
i need the path of each node as a string as the output.

can anyone help me??
Oct 9 '11 #1
0 1314

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: shaun | last post by:
Is it possible in XSLT to get the path to the current node as a string, maybe change one element and then navigate to the new resulting string? e.g. I have two documents I want to merge. The...
3
by: Tzvika Barenholz | last post by:
Hi all. Here's my problem: I have a tree linking macaddresses (bigints) in a tree structure. i want to get the path from node a to b. create table tree1(father bigint , child bigint); ...
9
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
6
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete...
6
by: Joe | last post by:
Hello All: Does anyone know the difference between the name and id attributes in an Html control? I noticed on PostBack that I can not retrieve the Request.Form("id_value") but I can retrieve...
1
by: Zhiv Kurilka | last post by:
Dear all, supposed I have xml file root> <a> <name>ddd</name> <b> <name>ggg</name> <c>10</c> </b> </a>
2
by: rbondalapati | last post by:
Hi I am trying to read xmlNode and validate user code used to do this is given below. i am able to load the XMLDocument. but the SelectSingleNode method call is always returning null value. ...
3
by: alhalayqa | last post by:
hi guys, how can distinguish between XML Node and HTML Node, using attributes or method .. thanks .
2
by: shapper | last post by:
Hello, I am trying to get the node "album" in a XML file given its "id" attribute: <gallery> <album id = "1" title="Intro" ....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.