Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
tramntn
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190

How to parse HTML tag

Hello everyone! i'm trying to parse HTML tag,

I see on this link to show How to parse XML
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800599/How_To_...

conn=(StreamConnection)Connector.open(url);
DocumentBuilderFactory docBuilderFactory= DocumentBuilderFactory. newInstance();
DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(conn.openInputStream());

 

DocumentBuilder seems just parse only XML, because when i try with html it will be error at this line

 

Document doc = docBuilder.parse(conn.openInputStream()); // (Error here, its ok with xml)

 

So anyone know how to parse html tag in BB please help!

 

Thanks in advance

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to parse HTML tag

And the error is?

 

How do you create the input stream?

 

That said, html does not have to be strict as XML.  For example most people write <p> but never write the </p> tag.  This will cause the XML parser to blow up with the parsing exception.  However most browsers cope with that.

 

So if you are going to be parsing html over which you have no control, then I think you will have to do it by yourself.  If you are going to be parsing html that you have control over and you know will be well formed, the the XML parser may work for you.