SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TXmlDoc Class Reference

#include <xml.h>

Collaboration diagram for TXmlDoc:

List of all members.

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.

: Ok(false), MsgStr(), Tok(){}
TXmlDoc::TXmlDoc ( const PXmlTok _Tok) [inline]

Definition at line 336 of file xml.h.

: Ok(!_Tok.Empty()), MsgStr(), Tok(_Tok){}
TXmlDoc::TXmlDoc ( TSIn ) [inline]

Definition at line 338 of file xml.h.

References Fail.

{Fail;}

Member Function Documentation

TStr TXmlDoc::GetMsgStr ( ) const [inline]

Definition at line 346 of file xml.h.

{return MsgStr;}
PXmlTok TXmlDoc::GetTagTok ( const TStr TagPath) const

Definition at line 1292 of file xml.cpp.

References TStr::Empty(), TXmlTok::GetStr(), TXmlTok::GetSym(), TXmlTok::GetTagTok(), TStr::SplitOnCh(), Tok, and xsyTag.

Referenced by GetTagTokV(), and PutTagTokStr().

                                                    {
  if (TagPath.Empty()){
    return Tok;
  } else {
    TStr TagNm; TStr RestTagPath; TagPath.SplitOnCh(TagNm, '|', RestTagPath);
    if ((Tok->GetSym()==xsyTag)&&(Tok->GetStr()==TagNm)){
      if (RestTagPath.Empty()){return Tok;}
      else {return Tok->GetTagTok(RestTagPath);}
    } else {
      return NULL;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool TXmlDoc::GetTagTokBoolArgVal ( const TStr TagPath,
const TStr ArgNm,
const bool &  DfVal = false 
) const

Definition at line 1326 of file xml.cpp.

References TXmlTok::GetBoolArgVal(), and IsTagTok().

                                                                  {
  PXmlTok TagTok;
  if (IsTagTok(TagPath, TagTok)){
    return TagTok->GetBoolArgVal(ArgNm, DfVal);}
  else {return DfVal;}
}

Here is the call graph for this function:

double TXmlDoc::GetTagTokFltArgVal ( const TStr TagPath,
const TStr ArgNm,
const double &  DfVal = 0 
) const

Definition at line 1342 of file xml.cpp.

References TXmlTok::GetFltArgVal(), and IsTagTok().

                                                                    {
  PXmlTok TagTok;
  if (IsTagTok(TagPath, TagTok)){
    return TagTok->GetFltArgVal(ArgNm, DfVal);}
  else {return DfVal;}
}

Here is the call graph for this function:

int TXmlDoc::GetTagTokIntArgVal ( const TStr TagPath,
const TStr ArgNm,
const int &  DfVal = 0 
) const

Definition at line 1334 of file xml.cpp.

References TXmlTok::GetIntArgVal(), and IsTagTok().

                                                                 {
  PXmlTok TagTok;
  if (IsTagTok(TagPath, TagTok)){
    return TagTok->GetIntArgVal(ArgNm, DfVal);}
  else {return DfVal;}
}

Here is the call graph for this function:

TStr TXmlDoc::GetTagTokStr ( const TStr TagPath) const [inline]

Definition at line 356 of file xml.h.

                                               {
    return GetTagTok(TagPath)->GetTokStr(false);}
TStr TXmlDoc::GetTagTokStrArgVal ( const TStr TagPath,
const TStr ArgNm,
const TStr DfVal = TStr() 
) const

Definition at line 1350 of file xml.cpp.

References TXmlTok::GetStrArgVal(), and IsTagTok().

                                                                  {
  PXmlTok TagTok;
  if (IsTagTok(TagPath, TagTok)){
    return TagTok->GetStrArgVal(ArgNm, DfVal);}
  else {return DfVal;}
}

Here is the call graph for this function:

void TXmlDoc::GetTagTokV ( const TStr TagPath,
TXmlTokV XmlTokV 
) const

Definition at line 1313 of file xml.cpp.

References TVec< TVal >::Add(), TVec< TVal >::Clr(), TPt< TRec >::Empty(), TXmlTok::GetStr(), TXmlTok::GetSubTok(), TXmlTok::GetSubToks(), TXmlTok::GetSym(), GetTagTok(), TStr::SplitOnLastCh(), Tok, and xsyTag.

                                                                     {
  XmlTokV.Clr();
  TStr PreTagPath; TStr TagNm; TagPath.SplitOnLastCh(PreTagPath, '|', TagNm);
  PXmlTok Tok=GetTagTok(PreTagPath);
  if (!Tok.Empty()){
    for (int SubTokN=0; SubTokN<Tok->GetSubToks(); SubTokN++){
      PXmlTok SubTok=Tok->GetSubTok(SubTokN);
      if ((SubTok->GetSym()==xsyTag)&&(SubTok->GetStr()==TagNm)){
        XmlTokV.Add(SubTok);}
    }
  }
}

Here is the call graph for this function:

TStr TXmlDoc::GetTagVal ( const TStr TagNm,
const bool &  XmlP 
) const [inline]

Definition at line 361 of file xml.h.

References TVec< TVal >::Len().

                                                            {
    TStrV ValV; GetTagValV(TagNm, XmlP, ValV);
    if (ValV.Len()>0){return ValV[0];} else {return "";}}

Here is the call graph for this function:

void TXmlDoc::GetTagValV ( const TStr TagNm,
const bool &  XmlP,
TStrV ValV 
) const [inline]

Definition at line 359 of file xml.h.

References IAssert.

                                                                          {
    IAssert(Ok); Tok->GetTagValV(TagNm, XmlP, ValV);}
PXmlTok TXmlDoc::GetTok ( ) const [inline]

Definition at line 347 of file xml.h.

References IAssert.

Referenced by LoadTxtElement().

{IAssert(Ok); return Tok;}

Here is the caller graph for this function:

TStr TXmlDoc::GetXmlStr ( const TStr Str) [static]

Definition at line 1358 of file xml.cpp.

References TUInt::GetStr(), and TChA::Len().

                                      {
  TChA ChA=Str;
  TChA XmlChA;
  for (int ChN=0; ChN<ChA.Len(); ChN++){
    uchar Ch=ChA[ChN];
    if ((' '<=Ch)&&(Ch<='~')){
      if (Ch=='&'){XmlChA+="&amp;";}
      else if (Ch=='>'){XmlChA+="&lt;";}
      else if (Ch=='<'){XmlChA+="&gt;";}
      else if (Ch=='\''){XmlChA+="&apos;";}
      else if (Ch=='\"'){XmlChA+="&quot;";}
      else {XmlChA+=Ch;}
    } else {
      XmlChA+="&#"; XmlChA+=TUInt::GetStr(Ch); XmlChA+=";";
    }
  }
  return XmlChA;
}

Here is the call graph for this function:

bool TXmlDoc::IsOk ( ) const [inline]

Definition at line 345 of file xml.h.

{return Ok;}
bool TXmlDoc::IsTagTok ( const TStr TagPath,
PXmlTok TagTok 
) const [inline]

Definition at line 350 of file xml.h.

References TPt< TRec >::Empty(), and IAssert.

Referenced by GetTagTokBoolArgVal(), GetTagTokFltArgVal(), GetTagTokIntArgVal(), and GetTagTokStrArgVal().

                                                            {
    IAssert(Ok); TagTok=GetTagTok(TagPath); return !TagTok.Empty();}

Here is the call graph for this function:

Here is the caller graph for this function:

bool TXmlDoc::IsTagTok ( const TStr TagPath) const [inline]

Definition at line 352 of file xml.h.

                                           {
    PXmlTok TagTok; return IsTagTok(TagPath, TagTok);}
static PXmlDoc TXmlDoc::Load ( TSIn SIn) [inline, static]

Definition at line 339 of file xml.h.

{return new TXmlDoc(SIn);}
PXmlDoc TXmlDoc::LoadStr ( const TStr Str) [static]

Definition at line 1437 of file xml.cpp.

References LoadTxt(), and New().

                                       {
  PSIn SIn=TStrIn::New(Str);
  return LoadTxt(SIn);
}

Here is the call graph for this function:

PXmlDoc TXmlDoc::LoadTxt ( TXmlLx Lx) [static]

Definition at line 1395 of file xml.cpp.

References TXmlLx::GetSym(), LoadTxtElement(), LoadTxtMiscStar(), New(), TXmlLx::Sym, xsyDocTypeDecl, and xsyXmlDecl.

Referenced by IsXLoadFromFileOk(), LoadStr(), LoadTxt(), TExpHelp::LoadXml(), and TPreproc::TPreproc().

                                  {
  PXmlDoc Doc=TXmlDoc::New();
  // [1]  document ::=  prolog element Misc*
  try {
    Lx.GetSym();
    // [22] prolog ::=  XMLDecl? Misc* (doctypedecl Misc*)?
    if (Lx.Sym==xsyXmlDecl){Lx.GetSym();}
    LoadTxtMiscStar(Lx);
    if (Lx.Sym==xsyDocTypeDecl){Lx.GetSym();}
    LoadTxtMiscStar(Lx);
    Doc->Tok=LoadTxtElement(Lx);
    LoadTxtMiscStar(Lx);
    Doc->Ok=true; Doc->MsgStr="Ok";
  }
  catch (PExcept& Except){
    Doc->Ok=false; Doc->MsgStr=Except->GetMsgStr();
  }
  return Doc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PXmlDoc TXmlDoc::LoadTxt ( const PSIn SIn,
const TXmlSpacing Spacing = xspIntact 
) [static]

Definition at line 1415 of file xml.cpp.

References LoadTxt().

                                                                   {
  TXmlLx Lx(SIn, Spacing); return LoadTxt(Lx);
}

Here is the call graph for this function:

PXmlDoc TXmlDoc::LoadTxt ( const TStr FNm,
const TXmlSpacing Spacing = xspIntact 
) [static]

Definition at line 1419 of file xml.cpp.

References LoadTxt(), and New().

                                                                   {
  PSIn SIn=TFIn::New(FNm); return LoadTxt(SIn, Spacing);
}

Here is the call graph for this function:

void TXmlDoc::LoadTxt ( const TStr FNm,
TXmlDocV XmlDocV,
const TXmlSpacing Spacing = xspIntact 
) [static]

Definition at line 1423 of file xml.cpp.

References TVec< TVal >::Add(), TVec< TVal >::Clr(), forever, LoadTxt(), New(), and TXmlLx::SkipWs().

                                                                {
  XmlDocV.Clr();
  PSIn SIn=TFIn::New(FNm);
  TXmlLx Lx(SIn, Spacing);
  PXmlDoc XmlDoc;
  forever {
    Lx.SkipWs();
    XmlDoc=LoadTxt(Lx);
    if (XmlDoc->IsOk()){XmlDocV.Add(XmlDoc);}
    else {break;}
  }
}

Here is the call graph for this function:

PXmlTok TXmlDoc::LoadTxtElement ( TXmlLx Lx) [static, private]

Definition at line 1243 of file xml.cpp.

References TXmlTok::AddSubTok(), TPt< TRec >::Empty(), TXmlLx::EThrow(), forever, TXmlTok::GetStr(), TStr::GetStr(), TXmlLx::GetSym(), GetTok(), MsgStr, TXmlLx::Sym, TXmlLx::TagNm, Tok, xsyComment, xsyETag, xsyPI, xsyQStr, xsySETag, xsySTag, xsyStr, and xsyWs.

Referenced by LoadTxt().

                                         {
  // [39]  element ::=  EmptyElemTag | STag content ETag
  PXmlTok Tok;
  if (Lx.Sym==xsySETag){
    Tok=TXmlTok::GetTok(Lx);
  } else
  if (Lx.Sym==xsySTag){
    Tok=TXmlTok::GetTok(Lx);
    forever {
      Lx.GetSym();
      if (Lx.Sym==xsyETag){
        if (Tok->GetStr()==Lx.TagNm){
          break;
        } else {
          TStr MsgStr=TStr("Invalid End-Tag '")+Lx.TagNm+
           "' ('"+Tok->GetStr()+"' expected).";
          Lx.EThrow(MsgStr);
        }
      } else {
        PXmlTok SubTok;
        switch (Lx.Sym){
          case xsySTag:
            SubTok=LoadTxtElement(Lx); break;
          case xsySETag:
          case xsyStr:
          case xsyQStr:
          case xsyWs:
            SubTok=TXmlTok::GetTok(Lx); break;
          case xsyPI:
          case xsyComment:
            break;
          default: Lx.EThrow("Content or End-Tag expected.");
        }
        if (!SubTok.Empty()){
          Tok->AddSubTok(SubTok);}
      }
    }
  } else
  if (Lx.Sym==xsyETag){
    TStr MsgStr=
     TStr("Xml-Element (Start-Tag or Empty-Element-Tag) required.")+
     TStr::GetStr(Lx.TagNm, " End-Tag </%s> encountered.");
    Lx.EThrow(MsgStr);
  } else {
    Lx.EThrow("Xml-Element (Start-Tag or Empty-Element-Tag) required.");
  }
  return Tok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TXmlDoc::LoadTxtMiscStar ( TXmlLx Lx) [static, private]

Definition at line 1237 of file xml.cpp.

References TXmlLx::GetSym(), TXmlLx::Sym, xsyComment, xsyPI, and xsyWs.

Referenced by LoadTxt(), and SkipTopTag().

                                       {
  // [27] Misc ::=  Comment | PI |  S
  while ((Lx.Sym==xsyComment)||(Lx.Sym==xsyPI)||(Lx.Sym==xsyWs)){
    Lx.GetSym();}
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PXmlDoc TXmlDoc::New ( ) [inline, static]

Definition at line 335 of file xml.h.

Referenced by LoadStr(), LoadTxt(), PutTagTokStr(), and SaveStr().

{return PXmlDoc(new TXmlDoc());}

Here is the caller graph for this function:

static PXmlDoc TXmlDoc::New ( const PXmlTok Tok) [inline, static]

Definition at line 337 of file xml.h.

{return PXmlDoc(new TXmlDoc(Tok));}
TXmlDoc& TXmlDoc::operator= ( const TXmlDoc ) [inline]

Definition at line 342 of file xml.h.

References Fail.

{Fail; return *this;}
void TXmlDoc::PutTagTokStr ( const TStr TagPath,
const TStr TokStr 
) const

Definition at line 1306 of file xml.cpp.

References TXmlTok::AddSubTok(), TXmlTok::ClrSubTok(), GetTagTok(), New(), Tok, and xsyStr.

                                                                        {
  PXmlTok Tok=GetTagTok(TagPath);
  Tok->ClrSubTok();
  PXmlTok StrTok=TXmlTok::New(xsyStr, TokStr);
  Tok->AddSubTok(StrTok);
}

Here is the call graph for this function:

void TXmlDoc::Save ( TSOut ) [inline]

Definition at line 340 of file xml.h.

References Fail.

{Fail;}
void TXmlDoc::SaveStr ( TStr Str)

Definition at line 1442 of file xml.cpp.

References TMOut::GetAsStr(), New(), and SaveTxt().

                              {
  PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
  SaveTxt(SOut);
  Str=MOut.GetAsStr();
}

Here is the call graph for this function:

void TXmlDoc::SaveTxt ( const PSOut SOut) [inline]

Definition at line 383 of file xml.h.

References TSOut::PutStr().

Referenced by SaveStr().

                                 {
    SOut->PutStr(GetTok()->GetTokStr());}

Here is the call graph for this function:

Here is the caller graph for this function:

void TXmlDoc::SaveTxt ( const TStr FNm,
const bool &  Append = false 
) [inline]

Definition at line 385 of file xml.h.

References TFOut::New().

                                                         {
    PSOut SOut=TFOut::New(FNm, Append); SaveTxt(SOut);}

Here is the call graph for this function:

bool TXmlDoc::SkipTopTag ( const PSIn SIn) [static]

Definition at line 1377 of file xml.cpp.

References TXmlLx::GetSym(), LoadTxtMiscStar(), Ok, TXmlLx::Sym, xspIntact, xsyDocTypeDecl, and xsyXmlDecl.

                                       {
  bool Ok=true;
  TXmlLx Lx(SIn, xspIntact);
  try {
    Lx.GetSym();
    // [22] prolog ::=  XMLDecl? Misc* (doctypedecl Misc*)?
    if (Lx.Sym==xsyXmlDecl){Lx.GetSym();}
    LoadTxtMiscStar(Lx);
    if (Lx.Sym==xsyDocTypeDecl){Lx.GetSym();}
    LoadTxtMiscStar(Lx);
    Ok=true;
  }
  catch (PExcept Except){
    Ok=false;
  }
  return Ok;
}

Here is the call graph for this function:


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.

Referenced by LoadTxtElement().

bool TXmlDoc::Ok [private]

Definition at line 328 of file xml.h.

Referenced by SkipTopTag().

PXmlTok TXmlDoc::Tok [private]

Definition at line 330 of file xml.h.

Referenced by GetTagTok(), GetTagTokV(), LoadTxtElement(), and PutTagTokStr().


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