Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #1002309 // findContainerTag - HTML/XML parsing, fixed tag name

JavaX fragment (include)

// tok must come from htmlTok
// returns all container tags found (including content) as CNC
// should be OK for both HTML and XML
static LL<S> findContainerTag(L<S> tok, S tag) {
  new LL<S> l;
  for (int i = 1; i < l(tok); i += 2)
    if (isOpeningTag(tok.get(i), tag)) {
      int j, level = 1;
      for (j = i+2; j < tok.size(); j += 2)
        if (isOpeningTag(tok.get(j), tag))
          ++level;
        else if (isTag(tok.get(j), "/" + tag)) {
          --level;
          if (level == 0) {
            l.add(subList(tok, i-1, j+2)); // actual CNC
            break;
          }
        }
      i = j;
    }
  ret l;
}

static LL<S> findContainerTag(S html, S tag) {
  ret findContainerTag(htmlTok(html), tag);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002309
Snippet name: findContainerTag - HTML/XML parsing, fixed tag name
Eternal ID of this version: #1002309/5
Text MD5: d7a992bd617145ec5928d2480beec6a4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-24 03:12:23
Source code size: 748 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 834 / 1066
Version history: 4 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1005097 - findContainerOrEmptyTag - HTML/XML parsing
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1007927 - findContainerTags - HTML/XML parsing
#1008404 - contentsOfPTags - HTML/XML parsing, extract <p> tags
#1008443 - findContainerTagWithParams - HTML/XML parsing, fixed tag name
#1008449 - findContainerTagDeep - HTML/XML parsing, fixed tag name
#1023876 - contentsOfContainerTags
#1028648 - findContainerTagWithClass
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)