Re: Parsing HTML
Joseph Kesselman <[email protected]> Tue, 27 May 2025 18:26:40 +0000
| Newsgroups | gmane.text.xml.xerces-j.user |
|---|---|
| Message-ID | <MN2PR12MB42213B29A27486A6F64AF8169E64A@MN2PR12MB4221.namprd12.prod.outlook.com> |
--_000_MN2PR12MB42213B29A27486A6F64AF8169E64AMN2PR12MB4221namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Supporting an HTML DOM, and being able serialize to HTML, does not necessar= ily imply being able to parse HTML. As far as I know, that last is not sup= ported by Xerces. I was able to (ab)use the W3C's _tidy_ tool to do some basic HTML parsing. = Inelegant but it sufficed for what I needed. -- /_ Joe Kesselman (he/him/his) -/ _) My Alexa skill for New Music/New Sounds fans: / https://www.amazon.com/dp/B09WJ3H657/ Caveat: Opinionated old geezer with overcompensated writer's block. May be = redundant, verbose, prolix, sesquipedalian, didactic, officious, or redunda= nt. ________________________________ From: Olivier Cailloux <[email protected]> Sent: Tuesday, May 27, 2025 1:08:55 PM To: [email protected] <[email protected]> Subject: Parsing HTML Dear list, Apache Xerces-J says that it implements DOM Level 1 HTML. I asked recently= about the bootstrapping support, which did not yield answers, so let me br= oaden the question. Can anyone point me towards some way of reading HTML (non XML<https://www.w= 3.org/TR/DOM-Level-1/introduction.html#ID-E7C3082>) files using Xerces-J? I= tried various things using org.apache.xerces.parsers.DOMParserImpl but par= sing this file<https://github.com/oliviercailloux/JARiS/blob/main/src/test/= resources/io/github/oliviercailloux/jaris/xml/Html/Simple.html> for example= (valid according to Nu validator<https://validator.nu/>) fails. I am ready to use a way that does not follow the W3C bootstrapping one, if = required. Thanks a lot! --_000_MN2PR12MB42213B29A27486A6F64AF8169E64AMN2PR12MB4221namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > </head> <body> <div dir=3D"auto" style=3D"font-family: Aptos, Aptos_MSFontService, -apple-= system, Roboto, Arial, Helvetica, sans-serif; font-size: 12pt;"> Supporting an HTML DOM, and being able serialize to HTML, does not necessar= ily imply being able to parse HTML. As far as I know, that last is no= t supported by Xerces.</div> <div dir=3D"auto" style=3D"font-family: Aptos, Aptos_MSFontService, -apple-= system, Roboto, Arial, Helvetica, sans-serif; font-size: 12pt;"> <br> </div> <div dir=3D"auto" style=3D"font-family: Aptos, Aptos_MSFontService, -apple-= system, Roboto, Arial, Helvetica, sans-serif; font-size: 12pt;"> I was able to (ab)use the W3C's _tidy_ tool to do some basic HTML parsing. = Inelegant but it sufficed for what I needed.</div> <div id=3D"ms-outlook-mobile-body-separator-line" dir=3D"auto"><br> </div> <div id=3D"ms-outlook-mobile-signature" dir=3D"auto" style=3D"font-family: = Aptos, Aptos_MSFontService, -apple-system, Roboto, Arial, Helvetica, sans-s= erif; font-size: 12pt;"> <div dir=3D"auto">--</div> <div dir=3D"auto"> /_ Joe Kesselman (he/him/his)</div> <div>-/ _) My Alexa skill for New Music/New Sounds fans:</div> <div> / https://www.amazon.com/dp/B09WJ3H657/</div> <div dir=3D"auto"><br> </div> <div dir=3D"auto">Caveat: Opinionated old geezer with overcompensated write= r's block. <span style=3D"font-size:12pt">May be redundant, verbose, p= rolix, sesquipedalian, didactic, officious, or redundant.</span></div> </div> <hr style=3D"display:inline-block;width:98%" tabindex=3D"-1"> <div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st= yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> Olivier Cailloux <= [email protected]><br> <b>Sent:</b> Tuesday, May 27, 2025 1:08:55 PM<br> <b>To:</b> [email protected] <[email protected]><br> <b>Subject:</b> Parsing HTML</font> <div> </div> </div> <div> <div>Dear list,</div> <div><br> </div> <div>Apache Xerces-J says that it implements DOM Level 1 HTML. I aske= d recently about the bootstrapping support, which did not yield answers, so= let me broaden the question. </div> <div><br> </div> <div>Can anyone point me towards some way of reading HTML (<a href=3D"https= ://www.w3.org/TR/DOM-Level-1/introduction.html#ID-E7C3082">non XML</a>) fil= es using Xerces-J? I tried various things using <span class=3D"x_mtk17= " style=3D"color:rgb(0,16,128); font-family:"Fira Code","Dro= id Sans Mono",monospace,monospace; font-size:14px; font-variant-ligatu= res:normal; orphans:2; widows:2; white-space:pre-wrap; background-color:rgb= (248,248,248); text-decoration-style:initial; text-decoration-color:initial= ">org</span><span class=3D"x_mtk1" style=3D"color:rgb(59,59,59); font-famil= y:"Fira Code","Droid Sans Mono",monospace,monospace; fo= nt-size:14px; font-variant-ligatures:normal; orphans:2; widows:2; white-spa= ce:pre-wrap; background-color:rgb(248,248,248); text-decoration-style:initi= al; text-decoration-color:initial">.</span><span class=3D"x_mtk17" style=3D= "color:rgb(0,16,128); font-family:"Fira Code","Droid Sans Mo= no",monospace,monospace; font-size:14px; font-variant-ligatures:normal= ; orphans:2; widows:2; white-space:pre-wrap; background-color:rgb(248,248,2= 48); text-decoration-style:initial; text-decoration-color:initial">apache</= span><span class=3D"x_mtk1" style=3D"color:rgb(59,59,59); font-family:"= ;Fira Code","Droid Sans Mono",monospace,monospace; font-size= :14px; font-variant-ligatures:normal; orphans:2; widows:2; white-space:pre-= wrap; background-color:rgb(248,248,248); text-decoration-style:initial; tex= t-decoration-color:initial">.</span><span class=3D"x_mtk17" style=3D"color:= rgb(0,16,128); font-family:"Fira Code","Droid Sans Mono"= ;,monospace,monospace; font-size:14px; font-variant-ligatures:normal; orpha= ns:2; widows:2; white-space:pre-wrap; background-color:rgb(248,248,248); te= xt-decoration-style:initial; text-decoration-color:initial">xerces</span><s= pan class=3D"x_mtk1" style=3D"color:rgb(59,59,59); font-family:"Fira C= ode","Droid Sans Mono",monospace,monospace; font-size:14px; = font-variant-ligatures:normal; orphans:2; widows:2; white-space:pre-wrap; b= ackground-color:rgb(248,248,248); text-decoration-style:initial; text-decor= ation-color:initial">.</span><span class=3D"x_mtk17" style=3D"color:rgb(0,1= 6,128); font-family:"Fira Code","Droid Sans Mono",monos= pace,monospace; font-size:14px; font-variant-ligatures:normal; orphans:2; w= idows:2; white-space:pre-wrap; background-color:rgb(248,248,248); text-deco= ration-style:initial; text-decoration-color:initial">parsers</span><span cl= ass=3D"x_mtk1" style=3D"color:rgb(59,59,59); font-family:"Fira Code&qu= ot;,"Droid Sans Mono",monospace,monospace; font-size:14px; font-v= ariant-ligatures:normal; orphans:2; widows:2; white-space:pre-wrap; backgro= und-color:rgb(248,248,248); text-decoration-style:initial; text-decoration-= color:initial">.</span><span class=3D"x_mtk17" style=3D"color:rgb(0,16,128)= ; font-family:"Fira Code","Droid Sans Mono",monospace,m= onospace; font-size:14px; font-variant-ligatures:normal; orphans:2; widows:= 2; white-space:pre-wrap; background-color:rgb(248,248,248); text-decoration= -style:initial; text-decoration-color:initial">DOMParserImpl</span> bu= t parsing <a href=3D"https://github.com/oliviercailloux/JARiS/blob/main= /src/test/resources/io/github/oliviercailloux/jaris/xml/Html/Simple.html">t= his file</a> for example (valid according to <a href=3D"https://v= alidator.nu/">Nu validator</a>) fails.</div> <div><br> </div> <div>I am ready to use a way that does not follow the W3C bootstrapping one= , if required.</div> <div><br> </div> <div>Thanks a lot!</div> <div><br> </div> <div><span></span></div> </div> </body> </html> --_000_MN2PR12MB42213B29A27486A6F64AF8169E64AMN2PR12MB4221namp_--