Thread: [Htmlparser-user] HTML parser project question
Brought to you by:
derrickoswald
From: Ray J. <ra...@mc...> - 2009-09-30 18:19:13
|
I am working on a project and am having a bit of trouble figuring out how to do what I want with the HTML parser. Basically what I want to do is parse a HTML file and find all the text boxes. I then want to read the ID attribute of each box and load a value into the value attribute and reload the html file. I am working on a program (Program A) that currently communicates with a micro controller. Program A communicates over RS 485 or ethernet. The communication part is complete and working. I make requests to the micro for information and also send updates to it. Program A currently displays information it receives from the micro in a tabular format. I created the GUI in Swing to display the information and allow the user to make changes to the system. What I am currently trying to accomplish is this. We would like to display the information in a web page with a graphic representation of the HVAC system being monitored. The client will produce an HTML page with said graphic representation and text boxes that are to be updated with particular sensor, setpoint and relay values of the clients choice.The current values are to be obtained from the micro . The ID of the sensor, setpoint of relay to be updated in each text box will be stored in the input tags ID attribute. The HTML page will be stored locally on the clients computer and Program A will load the HTML into a web browser when the client hit a button in Program A (which is connected to the micro). Before loading the HTML into a web browser I need Program A to parse the HTML and determine which value to load into which text box. Once Program A determines the values to be loaded and where to put them, it continually sends requests to the micro for the most updated values . Program A then updates the text boxes VALUE attribute with the correct value for that text box. I do need to continually update the text boxes and display the current value of the sensor, etc. I am having an issue determining how to parse the HTML page to find the <input> tags and get the IDs I need as well as updating the VALUE attribute of that <input> tag continually from Program A. I think that about covers it. If you have any questions , feel free to email me. Thank you in advance, Ray Ray A. Jaramillo Software Engineer Micro Control Systems 5877 Enterprise Parkway Fort Myers, Florida 33905 Phone: (239) 694-0089 Fax: (239) 694-0031 Web: <http://www.mcscontrols.com>www.mcscontrols.com |
From: Derrick O. <der...@gm...> - 2009-09-30 20:02:40
|
So, you need an in-memory image of your web page, for that HTMLParser provides a NodeList. Get the file, or text string and pass it to the parser and use a null filter to get everything: Parser parser = new Parser (); parser.setResource (...); NodeList list = parser.Parse (null); Then you need to find your input fields: NodeFilter filter = new NodeClassFilter (InputTag.class); NodeList inputs = list.extractAllNodesThatMatch (filter, true /* recursive */); Now cycle through your list looking at the attributes of the input tags: for (int i = 0; i < inputs.Length (); i++) { InputTag tag = inputs[i]; ... tag.getAttribute (String name) ... tag.setAttribute (String key, String value) } Then output the whole page: System.out.println (list.toHtml ()); On Wed, Sep 30, 2009 at 7:39 PM, Ray Jaramillo <ra...@mc...> wrote: > I am working on a project and am having a bit of trouble figuring out how > to do what I want with the HTML parser. > Basically what I want to do is parse a HTML file and find all the text > boxes. I then want to read the ID attribute of each box and load a value > into the value attribute and reload the html file. > > I am working on a program (Program A) that currently communicates with a > micro controller. Program A communicates over RS 485 or ethernet. The > communication part is complete and working. I make requests to the micro for > information and also send updates to it. Program A currently displays > information it receives from the micro in a tabular format. I created the > GUI in Swing to display the information and allow the user to make changes > to the system. > > What I am currently trying to accomplish is this. We would like to display > the information in a web page with a graphic representation of the HVAC > system being monitored. The client will produce an HTML page with said > graphic representation and text boxes that are to be updated with particular > sensor, setpoint and relay values of the clients choice.The current values > are to be obtained from the micro . The ID of the sensor, setpoint of relay > to be updated in each text box will be stored in the input tags ID > attribute. The HTML page will be stored locally on the clients computer and > Program A will load the HTML into a web browser when the client hit a button > in Program A (which is connected to the micro). > > Before loading the HTML into a web browser I need Program A to parse the > HTML and determine which value to load into which text box. Once Program A > determines the values to be loaded and where to put them, it continually > sends requests to the micro for the most updated values . Program A then > updates the text boxes VALUE attribute with the correct value for that text > box. I do need to continually update the text boxes and display the current > value of the sensor, etc. > > I am having an issue determining how to parse the HTML page to find the > <input> tags and get the IDs I need as well as updating the VALUE attribute > of that <input> tag continually from Program A. > > I think that about covers it. If you have any questions , feel free to > email me. > Thank you in advance, > Ray > > Ray A. Jaramillo > Software Engineer > Micro Control Systems > 5877 Enterprise Parkway > Fort Myers, Florida 33905 > Phone: (239) 694-0089 > Fax: (239) 694-0031 > Web: www.mcscontrols.com > > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Htmlparser-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlparser-user > > |