Parse But Not XML

Have a situation where I am forced to use an html source which contains no xml structure. I am pulling out bits of information that falls between the

tags. I am using Instr and mid to get the information. My problem is that I can’t figure out how to run thru the complete file. The script runs, hits the first set of tags, pulls the info then exits. Just not sure how to get script to get each

. In xml I know I can use For each to cycle thru. Any suggestions?

Off the top of my head I would Consider walking through the string with instr and the mid functions checking the instr return index, or you could possibly split it into an array of lines using tokenize or a combo of replace and tokenize

Sub Main ()
    html = "<h1>First Header</h1><div><h11>Blah<h1>Second Header</h1></h11><h1>Third Header</h1><h2>H2 Header<h2>"
    list = []
    re = CreateObject ("roRegex", ".*?<h1>(.*?)</h1>(.*)", "is")
    ma = re.Match (html)
    While ma.Count () > 2
        list.Push (ma [1])
        ma = re.Match (ma [2])
    End While
    Print list
End Sub

Nice example - one for the toolbox

Very nice and helpful. Thank you greatly. Have not used regular expression much in other scripts, thought it was little confusing. I will have to look more into it.
Thanks again

Why don’t you just give it the XML treatment with roXmlElemnet.parse()? And then walk the tree as if it were XML.

That will work with many HTMLs and even the remaining ones, most can be pre-patched for issues before a xml-parse.

Sorry for commenting on such an old post

“EnTerr” wrote:
Why don’t you just give it the XML treatment with roXmlElemnet.parse()? And then walk the tree as if it were XML.

That will work with many HTMLs and even the remaining ones, most can be pre-patched for issues before a xml-parse.

Without knowing what the parse is failing on how would I know what to pre-patch?

“quartern” wrote:
Sorry for commenting on such an old post
No sweat - the dev.forum moves at near light-speed :?: -
i mean there is a time dilation and to an external stationary observer is seems couple of years pass between e.g. a bug being reported and fixed :laughing:

Without knowing what the parse is failing on how would I know what to pre-patch?
Well, the “pre-patching” idea implies that you actually know in advance what’s wrong with the HTML that makes it un-parsable. In other words can’t feed it any random document from the World Wild Web. As of how to figure out where it fails, you can either

  • use validator to sniff what’s fishy, e.g. https://validator.w3.org/ - or

  • use the fact that roXmlElement.parse() returns partial result - call genXml() on that and see which sections are missing; mutate the html, rinse & repeat…

It can be tricky but is doable. Note using a roRegEx also implies knowing the document structure.