SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TXmlDoc Class Reference

#include <xml.h>

Public Member Functions

 TXmlDoc ()
 
 TXmlDoc (const PXmlTok &_Tok)
 
 TXmlDoc (TSIn &)
 
void Save (TSOut &)
 
TXmlDocoperator= (const TXmlDoc &)
 
bool IsOk () const
 
TStr GetMsgStr () const
 
PXmlTok GetTok () const
 
bool IsTagTok (const TStr &TagPath, PXmlTok &TagTok) const
 
bool IsTagTok (const TStr &TagPath) const
 
PXmlTok GetTagTok (const TStr &TagPath) const
 
void PutTagTokStr (const TStr &TagPath, const TStr &TokStr) const
 
TStr GetTagTokStr (const TStr &TagPath) const
 
void GetTagTokV (const TStr &TagPath, TXmlTokV &XmlTokV) const
 
void GetTagValV (const TStr &TagNm, const bool &XmlP, TStrV &ValV) const
 
TStr GetTagVal (const TStr &TagNm, const bool &XmlP) const
 
bool GetTagTokBoolArgVal (const TStr &TagPath, const TStr &ArgNm, const bool &DfVal=false) const
 
int GetTagTokIntArgVal (const TStr &TagPath, const TStr &ArgNm, const int &DfVal=0) const
 
double GetTagTokFltArgVal (const TStr &TagPath, const TStr &ArgNm, const double &DfVal=0) const
 
TStr GetTagTokStrArgVal (const TStr &TagPath, const TStr &ArgNm, const TStr &DfVal=TStr()) const
 
void SaveTxt (const PSOut &SOut)
 
void SaveTxt (const TStr &FNm, const bool &Append=false)
 
void SaveStr (TStr &Str)
 

Static Public Member Functions

static PXmlDoc New ()
 
static PXmlDoc New (const PXmlTok &Tok)
 
static PXmlDoc Load (TSIn &SIn)
 
static TStr GetXmlStr (const TStr &Str)
 
static bool SkipTopTag (const PSIn &SIn)
 
static PXmlDoc LoadTxt (TXmlLx &Lx)
 
static PXmlDoc LoadTxt (const PSIn &SIn, const TXmlSpacing &Spacing=xspIntact)
 
static PXmlDoc LoadTxt (const TStr &FNm, const TXmlSpacing &Spacing=xspIntact)
 
static void LoadTxt (const TStr &FNm, TXmlDocV &XmlDocV, const TXmlSpacing &Spacing=xspIntact)
 
static PXmlDoc LoadStr (const TStr &Str)
 

Static Private Member Functions

static void LoadTxtMiscStar (TXmlLx &Lx)
 
static PXmlTok LoadTxtElement (TXmlLx &Lx)
 

Private Attributes

TCRef CRef
 
bool Ok
 
TStr MsgStr
 
PXmlTok Tok
 

Friends

class TPt< TXmlDoc >
 

Detailed Description

Definition at line 326 of file xml.h.

Constructor & Destructor Documentation

TXmlDoc::TXmlDoc ( )
inline

Definition at line 334 of file xml.h.

334 : Ok(false), MsgStr(), Tok(){}
TStr MsgStr
Definition: xml.h:329
PXmlTok Tok
Definition: xml.h:330
bool Ok
Definition: xml.h:328
TXmlDoc::TXmlDoc ( const PXmlTok _Tok)
inline

Definition at line 336 of file xml.h.

336 : Ok(!_Tok.Empty()), MsgStr(), Tok(_Tok){}
TStr MsgStr
Definition: xml.h:329
PXmlTok Tok
Definition: xml.h:330
bool Ok
Definition: xml.h:328
bool Empty() const
Definition: bd.h:501
TXmlDoc::TXmlDoc ( TSIn )
inline

Definition at line 338 of file xml.h.

338 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

TStr TXmlDoc::GetMsgStr ( ) const
inline

Definition at line 346 of file xml.h.

346 {return MsgStr;}
TStr MsgStr
Definition: xml.h:329
PXmlTok TXmlDoc::GetTagTok ( const TStr TagPath) const

Definition at line 1298 of file xml.cpp.

1298  {
1299  if (TagPath.Empty()){
1300  return Tok;
1301  } else {
1302  TStr TagNm; TStr RestTagPath; TagPath.SplitOnCh(TagNm, '|', RestTagPath);
1303  if ((Tok->GetSym()==xsyTag)&&(Tok->GetStr()==TagNm)){
1304  if (RestTagPath.Empty()){return Tok;}
1305  else {return Tok->GetTagTok(RestTagPath);}
1306  } else {
1307  return NULL;
1308  }
1309  }
1310 }
Definition: xml.h:93
PXmlTok Tok
Definition: xml.h:330
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
Definition: dt.cpp:901
TStr GetStr() const
Definition: xml.h:244
PXmlTok GetTagTok(const TStr &TagPath) const
Definition: xml.cpp:1142
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
TXmlLxSym GetSym() const
Definition: xml.h:241
bool TXmlDoc::GetTagTokBoolArgVal ( const TStr TagPath,
const TStr ArgNm,
const bool &  DfVal = false 
) const

Definition at line 1332 of file xml.cpp.

1333  {
1334  PXmlTok TagTok;
1335  if (IsTagTok(TagPath, TagTok)){
1336  return TagTok->GetBoolArgVal(ArgNm, DfVal);}
1337  else {return DfVal;}
1338 }
bool IsTagTok(const TStr &TagPath, PXmlTok &TagTok) const
Definition: xml.h:350
Definition: bd.h:196
double TXmlDoc::GetTagTokFltArgVal ( const TStr TagPath,
const TStr ArgNm,
const double &  DfVal = 0 
) const

Definition at line 1348 of file xml.cpp.

1349  {
1350  PXmlTok TagTok;
1351  if (IsTagTok(TagPath, TagTok)){
1352  return TagTok->GetFltArgVal(ArgNm, DfVal);}
1353  else {return DfVal;}
1354 }
bool IsTagTok(const TStr &TagPath, PXmlTok &TagTok) const
Definition: xml.h:350
Definition: bd.h:196
int TXmlDoc::GetTagTokIntArgVal ( const TStr TagPath,
const TStr ArgNm,
const int &  DfVal = 0 
) const

Definition at line 1340 of file xml.cpp.

1341  {
1342  PXmlTok TagTok;
1343  if (IsTagTok(TagPath, TagTok)){
1344  return TagTok->GetIntArgVal(ArgNm, DfVal);}
1345  else {return DfVal;}
1346 }
bool IsTagTok(const TStr &TagPath, PXmlTok &TagTok) const
Definition: xml.h:350
Definition: bd.h:196
TStr TXmlDoc::GetTagTokStr ( const TStr TagPath) const
inline

Definition at line 356 of file xml.h.

356  {
357  return GetTagTok(TagPath)->GetTokStr(false);}
TStr GetTokStr(const bool &XmlP=true) const
Definition: xml.h:316
PXmlTok GetTagTok(const TStr &TagPath) const
Definition: xml.cpp:1298
TStr TXmlDoc::GetTagTokStrArgVal ( const TStr TagPath,
const TStr ArgNm,
const TStr DfVal = TStr() 
) const

Definition at line 1356 of file xml.cpp.

1357  {
1358  PXmlTok TagTok;
1359  if (IsTagTok(TagPath, TagTok)){
1360  return TagTok->GetStrArgVal(ArgNm, DfVal);}
1361  else {return DfVal;}
1362 }
bool IsTagTok(const TStr &TagPath, PXmlTok &TagTok) const
Definition: xml.h:350
Definition: bd.h:196
void TXmlDoc::GetTagTokV ( const TStr TagPath,
TXmlTokV XmlTokV 
) const

Definition at line 1319 of file xml.cpp.

1319  {
1320  XmlTokV.Clr();
1321  TStr PreTagPath; TStr TagNm; TagPath.SplitOnLastCh(PreTagPath, '|', TagNm);
1322  PXmlTok Tok=GetTagTok(PreTagPath);
1323  if (!Tok.Empty()){
1324  for (int SubTokN=0; SubTokN<Tok->GetSubToks(); SubTokN++){
1325  PXmlTok SubTok=Tok->GetSubTok(SubTokN);
1326  if ((SubTok->GetSym()==xsyTag)&&(SubTok->GetStr()==TagNm)){
1327  XmlTokV.Add(SubTok);}
1328  }
1329  }
1330 }
Definition: xml.h:93
PXmlTok Tok
Definition: xml.h:330
bool Empty() const
Definition: bd.h:501
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
PXmlTok GetTagTok(const TStr &TagPath) const
Definition: xml.cpp:1298
Definition: dt.h:412
Definition: bd.h:196
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void SplitOnLastCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
Definition: dt.cpp:912
TStr TXmlDoc::GetTagVal ( const TStr TagNm,
const bool &  XmlP 
) const
inline

Definition at line 361 of file xml.h.

361  {
362  TStrV ValV; GetTagValV(TagNm, XmlP, ValV);
363  if (ValV.Len()>0){return ValV[0];} else {return "";}}
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void GetTagValV(const TStr &TagNm, const bool &XmlP, TStrV &ValV) const
Definition: xml.h:359
void TXmlDoc::GetTagValV ( const TStr TagNm,
const bool &  XmlP,
TStrV ValV 
) const
inline

Definition at line 359 of file xml.h.

359  {
360  IAssert(Ok); Tok->GetTagValV(TagNm, XmlP, ValV);}
#define IAssert(Cond)
Definition: bd.h:262
void GetTagValV(const TStr &TagNm, const bool &XmlP, TStrV &ValV) const
Definition: xml.cpp:1171
PXmlTok Tok
Definition: xml.h:330
bool Ok
Definition: xml.h:328
PXmlTok TXmlDoc::GetTok ( ) const
inline

Definition at line 347 of file xml.h.

347 {IAssert(Ok); return Tok;}
#define IAssert(Cond)
Definition: bd.h:262
PXmlTok Tok
Definition: xml.h:330
bool Ok
Definition: xml.h:328
TStr TXmlDoc::GetXmlStr ( const TStr Str)
static

Definition at line 1364 of file xml.cpp.

1364  {
1365  TChA ChA=Str;
1366  TChA XmlChA;
1367  for (int ChN=0; ChN<ChA.Len(); ChN++){
1368  uchar Ch=ChA[ChN];
1369  if ((' '<=Ch)&&(Ch<='~')){
1370  if (Ch=='&'){XmlChA+="&amp;";}
1371  else if (Ch=='>'){XmlChA+="&lt;";}
1372  else if (Ch=='<'){XmlChA+="&gt;";}
1373  else if (Ch=='\''){XmlChA+="&apos;";}
1374  else if (Ch=='\"'){XmlChA+="&quot;";}
1375  else {XmlChA+=Ch;}
1376  } else {
1377  XmlChA+="&#"; XmlChA+=TUInt::GetStr(Ch); XmlChA+=";";
1378  }
1379  }
1380  return XmlChA;
1381 }
int Len() const
Definition: dt.h:259
TStr GetStr() const
Definition: dt.h:1282
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
bool TXmlDoc::IsOk ( ) const
inline

Definition at line 345 of file xml.h.

345 {return Ok;}
bool Ok
Definition: xml.h:328
bool TXmlDoc::IsTagTok ( const TStr TagPath,
PXmlTok TagTok 
) const
inline

Definition at line 350 of file xml.h.

350  {
351  IAssert(Ok); TagTok=GetTagTok(TagPath); return !TagTok.Empty();}
#define IAssert(Cond)
Definition: bd.h:262
bool Ok
Definition: xml.h:328
bool Empty() const
Definition: bd.h:501
PXmlTok GetTagTok(const TStr &TagPath) const
Definition: xml.cpp:1298
bool TXmlDoc::IsTagTok ( const TStr TagPath) const
inline

Definition at line 352 of file xml.h.

352  {
353  PXmlTok TagTok; return IsTagTok(TagPath, TagTok);}
bool IsTagTok(const TStr &TagPath, PXmlTok &TagTok) const
Definition: xml.h:350
Definition: bd.h:196
static PXmlDoc TXmlDoc::Load ( TSIn SIn)
inlinestatic

Definition at line 339 of file xml.h.

339 {return new TXmlDoc(SIn);}
TXmlDoc()
Definition: xml.h:334
PXmlDoc TXmlDoc::LoadStr ( const TStr Str)
static

Definition at line 1443 of file xml.cpp.

1443  {
1444  PSIn SIn=TStrIn::New(Str);
1445  return LoadTxt(SIn);
1446 }
static PSIn New(const TStr &Str)
Definition: dt.h:711
static PXmlDoc LoadTxt(TXmlLx &Lx)
Definition: xml.cpp:1401
PXmlDoc TXmlDoc::LoadTxt ( TXmlLx Lx)
static

Definition at line 1401 of file xml.cpp.

1401  {
1402  PXmlDoc Doc=TXmlDoc::New();
1403  // [1] document ::= prolog element Misc*
1404  try {
1405  Lx.GetSym();
1406  // [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
1407  if (Lx.Sym==xsyXmlDecl){Lx.GetSym();}
1408  LoadTxtMiscStar(Lx);
1409  if (Lx.Sym==xsyDocTypeDecl){Lx.GetSym();}
1410  LoadTxtMiscStar(Lx);
1411  Doc->Tok=LoadTxtElement(Lx);
1412  LoadTxtMiscStar(Lx);
1413  Doc->Ok=true; Doc->MsgStr="Ok";
1414  }
1415  catch (PExcept& Except){
1416  Doc->Ok=false; Doc->MsgStr=Except->GetMsgStr();
1417  }
1418  return Doc;
1419 }
TXmlLxSym GetSym()
Definition: xml.cpp:757
static PXmlTok LoadTxtElement(TXmlLx &Lx)
Definition: xml.cpp:1249
Definition: bd.h:196
TXmlLxSym Sym
Definition: xml.h:139
static void LoadTxtMiscStar(TXmlLx &Lx)
Definition: xml.cpp:1243
static PXmlDoc New()
Definition: xml.h:335
Definition: xml.h:91
PXmlDoc TXmlDoc::LoadTxt ( const PSIn SIn,
const TXmlSpacing Spacing = xspIntact 
)
static

Definition at line 1421 of file xml.cpp.

1421  {
1422  TXmlLx Lx(SIn, Spacing); return LoadTxt(Lx);
1423 }
Definition: xml.h:98
static PXmlDoc LoadTxt(TXmlLx &Lx)
Definition: xml.cpp:1401
PXmlDoc TXmlDoc::LoadTxt ( const TStr FNm,
const TXmlSpacing Spacing = xspIntact 
)
static

Definition at line 1425 of file xml.cpp.

1425  {
1426  PSIn SIn=TFIn::New(FNm); return LoadTxt(SIn, Spacing);
1427 }
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
static PXmlDoc LoadTxt(TXmlLx &Lx)
Definition: xml.cpp:1401
void TXmlDoc::LoadTxt ( const TStr FNm,
TXmlDocV XmlDocV,
const TXmlSpacing Spacing = xspIntact 
)
static

Definition at line 1429 of file xml.cpp.

1430  {
1431  XmlDocV.Clr();
1432  PSIn SIn=TFIn::New(FNm);
1433  TXmlLx Lx(SIn, Spacing);
1434  PXmlDoc XmlDoc;
1435  forever {
1436  Lx.SkipWs();
1437  XmlDoc=LoadTxt(Lx);
1438  if (XmlDoc->IsOk()){XmlDocV.Add(XmlDoc);}
1439  else {break;}
1440  }
1441 }
#define forever
Definition: bd.h:6
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
Definition: xml.h:98
static PXmlDoc LoadTxt(TXmlLx &Lx)
Definition: xml.cpp:1401
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
PXmlTok TXmlDoc::LoadTxtElement ( TXmlLx Lx)
staticprivate

Definition at line 1249 of file xml.cpp.

1249  {
1250  // [39] element ::= EmptyElemTag | STag content ETag
1251  PXmlTok Tok;
1252  if (Lx.Sym==xsySETag){
1253  Tok=TXmlTok::GetTok(Lx);
1254  } else
1255  if (Lx.Sym==xsySTag){
1256  Tok=TXmlTok::GetTok(Lx);
1257  forever {
1258  Lx.GetSym();
1259  if (Lx.Sym==xsyETag){
1260  if (Tok->GetStr()==Lx.TagNm){
1261  break;
1262  } else {
1263  TStr MsgStr=TStr("Invalid End-Tag '")+Lx.TagNm+
1264  "' ('"+Tok->GetStr()+"' expected).";
1265  Lx.EThrow(MsgStr);
1266  }
1267  } else {
1268  PXmlTok SubTok;
1269  switch (Lx.Sym){
1270  case xsySTag:
1271  SubTok=LoadTxtElement(Lx); break;
1272  case xsySETag:
1273  case xsyStr:
1274  case xsyQStr:
1275  case xsyWs:
1276  SubTok=TXmlTok::GetTok(Lx); break;
1277  case xsyPI:
1278  case xsyComment:
1279  break;
1280  default: Lx.EThrow("Content or End-Tag expected.");
1281  }
1282  if (!SubTok.Empty()){
1283  Tok->AddSubTok(SubTok);}
1284  }
1285  }
1286  } else
1287  if (Lx.Sym==xsyETag){
1288  TStr MsgStr=
1289  TStr("Xml-Element (Start-Tag or Empty-Element-Tag) required.")+
1290  TStr::GetStr(Lx.TagNm, " End-Tag </%s> encountered.");
1291  Lx.EThrow(MsgStr);
1292  } else {
1293  Lx.EThrow("Xml-Element (Start-Tag or Empty-Element-Tag) required.");
1294  }
1295  return Tok;
1296 }
TStr MsgStr
Definition: xml.h:329
TXmlLxSym GetSym()
Definition: xml.cpp:757
TStr TagNm
Definition: xml.h:141
Definition: xml.h:93
Definition: xml.h:91
PXmlTok Tok
Definition: xml.h:330
#define forever
Definition: bd.h:6
bool Empty() const
Definition: bd.h:501
Definition: xml.h:90
void EThrow(const TStr &MsgStr) const
Definition: xml.cpp:885
Definition: xml.h:93
Definition: xml.h:93
Definition: xml.h:93
static PXmlTok GetTok(TXmlLx &Lx)
Definition: xml.cpp:1228
TStr GetStr() const
Definition: dt.h:681
Definition: xml.h:93
Definition: dt.h:412
static PXmlTok LoadTxtElement(TXmlLx &Lx)
Definition: xml.cpp:1249
Definition: xml.h:90
Definition: bd.h:196
TXmlLxSym Sym
Definition: xml.h:139
void TXmlDoc::LoadTxtMiscStar ( TXmlLx Lx)
staticprivate

Definition at line 1243 of file xml.cpp.

1243  {
1244  // [27] Misc ::= Comment | PI | S
1245  while ((Lx.Sym==xsyComment)||(Lx.Sym==xsyPI)||(Lx.Sym==xsyWs)){
1246  Lx.GetSym();}
1247 }
TXmlLxSym GetSym()
Definition: xml.cpp:757
Definition: xml.h:91
Definition: xml.h:90
Definition: xml.h:90
TXmlLxSym Sym
Definition: xml.h:139
static PXmlDoc TXmlDoc::New ( )
inlinestatic

Definition at line 335 of file xml.h.

335 {return PXmlDoc(new TXmlDoc());}
TPt< TXmlDoc > PXmlDoc
Definition: xml.h:326
TXmlDoc()
Definition: xml.h:334
static PXmlDoc TXmlDoc::New ( const PXmlTok Tok)
inlinestatic

Definition at line 337 of file xml.h.

337 {return PXmlDoc(new TXmlDoc(Tok));}
TPt< TXmlDoc > PXmlDoc
Definition: xml.h:326
TXmlDoc()
Definition: xml.h:334
TXmlDoc& TXmlDoc::operator= ( const TXmlDoc )
inline

Definition at line 342 of file xml.h.

342 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void TXmlDoc::PutTagTokStr ( const TStr TagPath,
const TStr TokStr 
) const

Definition at line 1312 of file xml.cpp.

1312  {
1313  PXmlTok Tok=GetTagTok(TagPath);
1314  Tok->ClrSubTok();
1315  PXmlTok StrTok=TXmlTok::New(xsyStr, TokStr);
1316  Tok->AddSubTok(StrTok);
1317 }
PXmlTok Tok
Definition: xml.h:330
static PXmlTok New()
Definition: xml.h:212
Definition: xml.h:93
PXmlTok GetTagTok(const TStr &TagPath) const
Definition: xml.cpp:1298
Definition: bd.h:196
void TXmlDoc::Save ( TSOut )
inline

Definition at line 340 of file xml.h.

340 {Fail;}
#define Fail
Definition: bd.h:238
void TXmlDoc::SaveStr ( TStr Str)

Definition at line 1448 of file xml.cpp.

1448  {
1449  PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
1450  SaveTxt(SOut);
1451  Str=MOut.GetAsStr();
1452 }
void SaveTxt(const PSOut &SOut)
Definition: xml.h:383
static PSOut New(const int &MxBfL=1024)
Definition: fl.h:506
TStr GetAsStr() const
Definition: fl.cpp:869
Definition: fl.h:495
Definition: bd.h:196
void TXmlDoc::SaveTxt ( const PSOut SOut)
inline

Definition at line 383 of file xml.h.

383  {
384  SOut->PutStr(GetTok()->GetTokStr());}
PXmlTok GetTok() const
Definition: xml.h:347
void TXmlDoc::SaveTxt ( const TStr FNm,
const bool &  Append = false 
)
inline

Definition at line 385 of file xml.h.

385  {
386  PSOut SOut=TFOut::New(FNm, Append); SaveTxt(SOut);}
void SaveTxt(const PSOut &SOut)
Definition: xml.h:383
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
Definition: bd.h:196
bool TXmlDoc::SkipTopTag ( const PSIn SIn)
static

Definition at line 1383 of file xml.cpp.

1383  {
1384  bool Ok=true;
1385  TXmlLx Lx(SIn, xspIntact);
1386  try {
1387  Lx.GetSym();
1388  // [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
1389  if (Lx.Sym==xsyXmlDecl){Lx.GetSym();}
1390  LoadTxtMiscStar(Lx);
1391  if (Lx.Sym==xsyDocTypeDecl){Lx.GetSym();}
1392  LoadTxtMiscStar(Lx);
1393  Ok=true;
1394  }
1395  catch (PExcept Except){
1396  Ok=false;
1397  }
1398  return Ok;
1399 }
bool Ok
Definition: xml.h:328
Definition: xml.h:96
Definition: xml.h:98
Definition: bd.h:196
static void LoadTxtMiscStar(TXmlLx &Lx)
Definition: xml.cpp:1243
Definition: xml.h:91

Friends And Related Function Documentation

friend class TPt< TXmlDoc >
friend

Definition at line 326 of file xml.h.

Member Data Documentation

TCRef TXmlDoc::CRef
private

Definition at line 326 of file xml.h.

TStr TXmlDoc::MsgStr
private

Definition at line 329 of file xml.h.

bool TXmlDoc::Ok
private

Definition at line 328 of file xml.h.

PXmlTok TXmlDoc::Tok
private

Definition at line 330 of file xml.h.


The documentation for this class was generated from the following files: