1)gpt@C͓

pase.cpp/pase.h(C++Builder/Borland C++)

UNIXgcc̃[U[
nkf -ed pase.cpp > pase.cc
VtgJISEUCɕR[hϊB
pase.cc/pase.h


2)vO̍

STEP1

  wb_Ɛ錾̗

  #include "parse.h"
  parser ps;

STEP2

  XMLt@C̓ǂݍ݂́A
  ꕶ͂B

  while (ifs.get(c), ifs.good()) {
    if (ps.step(c)) break;
  }
  ܂,
  while ((c = getchar(c)) != EOF) {
    if (ps.step((char)c)) break;
  }

  ferror()/std::good()ȂǂIOG[`FbNA

STEP3

  paser::checkerror()paser::acceptable()
  `FbN

  parser::checkerror()^̏ꍇA
   A^O>>><Ȃ

  parser::acceptable()^̏ꍇA
   ĂȂ^OAXMLƂĊĂ
    
  parser::checkerror()Ups.acceptable()ȔꍇA
   XML̍Ō܂œǂ߂ĂȂ傿؂Ă

STEP4

  hLg̖{̂tagrecłB
  p[XIhLparser::rootŎQƂB

  tagrec *root = ps.root; // parser ps;

  m[hQƂ@path\bhgp
  ́AOS̃t@C̎Qƕ@ɎĂB
@"/html/body/table"(΃pXŃ[g)
  "table/tr/td"(΃pXŃm[h̉)

  std::vector<tagrec *> titles;
  root->path(titles, "/html/head/title"); // XHTML̃^Cǧ
  printf("^Cg%s\n", titles[0]->value.c_str());
  //߂l͈vm[ȟ

  ^Ow肵Ĉʒu̕sȃm[h邱ƂłB
@[g猟ȂSẴm[hA
  m[hȂ΂ȉ̎}猟B

  std::vector<tagrec *> imgs, pis;
  root->find(imgs, "img"); // IMG^O
  root->find(pis, "?xml"); // XML
  root->find(pis, "?xml-stylesheet"); // XML
  //߂l͔m[ȟ

  m[h̑l邱ƂłB
  ʂ͑=l̃yAłB

  std::vector<tagrec *> pis;
  std::pair<std::string, std::string> encoding;
  root->find(pis, "?xml");
  if (pixml->scanattr(v, "encoding")) // GR[fBO 
    printf("%s = \"%s\"\n", v.first, v.second);
  root->find(pis, "?xml-stylesheet");
  if (pixml->scanattr(v, "href"))  // X^CV[g
    printf("%s = \"%s\"\n", v.first, v.second);
  // ߂l͐^Ȃ猩AȂ΂ȂB

STEP5

  ҏWp̃\bh͖B܂̂ƂA
  hLgc[̕ҏẂAc[T
@m[h̑}/폜AeLXg̕ύX𒼐ڍsB
  c[͐eq̑oNȂ̂ŁA
@OS̃fBNgc[̑Ɠv̂łB

  owner:̃m[h̐e([gȂNULL)
  child:Ԃ牺m[h̃Xg

  m[hdeleteō폜΂̉̎}͑SďB
  A폜ꍇɂ́A̐e(owner|C^)
  child|C^Xgw肷邱ƁB

STEP6

  vOŕҏWhLgc[
@Ăxml`ŕۑ邱ƂłB
  dump()\bhɂāÃm[hȉ̑SĂ
  ĂXML̓eł镶ɕϊłB
  ̕t@CɏoXMLt@CɂȂB

  std::cout << root->dump();
