40 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(
SXmlAttr_t); }
61 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(
SXmlNode_t); }
72 std::ostream *
fOut{
nullptr};
82 fOut =
new std::ofstream(filename);
131 int len = strlen(str);
135 fOut->write(str, len);
151 for (
int n = 0;
n < cnt;
n++)
154 for (
int n = 0;
n < cnt;
n++)
198 fInp =
new std::ifstream(filename);
204 fInpStrLen = !filename ? 0 : strlen(filename);
276 if (strncmp(beg, entity->
GetName(), len) == 0)
292 fInp->get(buf, maxsize, 0);
293 resultsize = strlen(buf);
295 resultsize = strlcpy(buf,
fInpStr, maxsize);
296 if (resultsize >= maxsize)
297 resultsize = maxsize - 1;
320 curr = newbuf + (curr -
fBuf);
365 for (
int n = 0;
n < sz;
n++) {
386 if ((symb > 26) && (symb !=
' '))
392 if (tillendl && (symb == 10))
403 int len = strlen(str);
410 if (*str++ != *curr++)
421 int len = strlen(str);
429 const char *chk0 = curr;
430 const char *chk = str;
433 if (*chk++ != *chk0++) {
450 return (((symb >=
'a') && (symb <=
'z')) || ((symb >=
'A') && (symb <=
'Z')) || (symb ==
'_') ||
451 ((symb >= 0xc0) && (symb <= 0xd6)) || ((symb >= 0xd8) && (symb <= 0xf6)) || (symb > 0xf8));
459 unsigned char symb = (
unsigned char)*
fCurrent;
472 symb = (
unsigned char)*curr;
473 ok =
GoodStartSymbol(symb) || ((symb >=
'0') && (symb <=
'9')) || (symb ==
':') || (symb ==
'-') ||
474 (symb ==
'.') || (symb == 0xb7);
504 char *curr =
fCurrent + curr_offset;
516 if ((*curr !=
'\"') && (*curr !=
'\''))
525 return curr - (
fCurrent + curr_offset) + 1;
551 if (!xmlnode || !
name)
588 sscanf(attr,
"%d", &res);
601 int namelen =
name ? strlen(
name) : 0;
602 int valuelen = value ? strlen(value) : 0;
607 strncpy(attrname,
name, namelen + 1);
610 attrname += (namelen + 1);
612 strncpy(attrname, value, valuelen + 1);
669 node->
fAttr =
nullptr;
682 if (attr && (node->
fNs == attr))
719 return attrname + strlen(attrname) + 1;
727 int namelen =
name ? strlen(
name) : 0;
737 int contlen = content ? strlen(content) : 0;
756 int namelen = strlen(
name);
757 char *nsname =
new char[namelen + 7];
761 node->
fAttr =
nullptr;
765 node->
fAttr = nsattr;
766 nsattr->
fNext = first;
792 if (nsname && (strncmp(nsname,
"xmlns:", 6) == 0))
811 if (!parent || !child)
836 if (!parent || !child)
868 Error(
"InsertChildAfter",
"Specified afternode is not in childs list of parent node");
879 anode->
fNext = cnode;
890 if (!xmlnode || !comment)
893 int commentlen = strlen(comment);
927 if (!xmlnode || !
line)
930 int linelen = strlen(
line);
964 int alternate,
const char *media,
const char *charset)
966 if (!xmlnode || !href || !type)
969 const char *nodename =
"xml-stylesheet";
970 int nodenamelen = strlen(nodename);
977 NewAttr(node,
nullptr,
"alternate", (alternate > 0) ?
"yes" :
"no");
980 NewAttr(node,
nullptr,
"title", title);
982 NewAttr(node,
nullptr,
"href", href);
983 NewAttr(node,
nullptr,
"type", type);
986 NewAttr(node,
nullptr,
"media", media);
988 NewAttr(node,
nullptr,
"charset", charset);
997 int alternate,
const char *media,
const char *charset)
1026 if (parent->
fChild == node) {
1032 while (ch->
fNext != node)
1040 node->
fNext =
nullptr;
1122 len = strlen(content);
1127 strncpy(nameptr, content, len);
1140 if (!xmlnode || !content)
1143 len = strlen(content);
1148 strncpy(nameptr, content, len);
1181 if (!xmlnode || !realnode)
1196 if (!xmlnode || !realnode)
1273 NewAttr(vernode,
nullptr,
"version", version);
1368 if (!fname || !*fname)
1371 std::filesystem::path rel = std::filesystem::proximate(fname, std::filesystem::current_path());
1374 if (rel.is_absolute())
1378 return rel.empty() || (*rel.begin() !=
"..");
1388 if (!filename || !*filename)
1390 if (maxbuf < 100000)
1394 Error(
"ParseFile",
"Fail open XML file %s", filename);
1405 if (!xmlstring || !*xmlstring)
1468 const char *value =
GetAttr(vernode,
"version");
1474 return strcmp(version, value) == 0;
1486 if (!res || !xmlnode)
1491 SaveNode(xmlnode, &out, layout, 0);
1508 if (resvalue <= 0) {
1524 int len = strlen(str);
1527 char *res =
new char[len + 1];
1528 strncpy(res, str, len + 1);
1537 if (!str || (len == 0))
1539 char *res =
new char[len + 1];
1540 strncpy(res, str, len);
1556 node->
fNs =
nullptr;
1557 node->
fAttr =
nullptr;
1560 node->
fNext =
nullptr;
1579 attr->
fNext =
nullptr;
1602 if (strcmp(nsname,
name) == 0)
1625 *(copyname++) = *(++colon);
1634 while (srclen > 0) {
1635 if (*source ==
'&') {
1636 if ((srclen > 3) && (*(source + 1) ==
'l') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1640 }
else if ((srclen > 3) && (*(source + 1) ==
'g') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1644 }
else if ((srclen > 4) && (*(source + 1) ==
'a') && (*(source + 2) ==
'm') && (*(source + 3) ==
'p') &&
1645 (*(source + 4) ==
';')) {
1649 }
else if ((srclen > 5) && (*(source + 1) ==
'q') && (*(source + 2) ==
'u') && (*(source + 3) ==
'o') &&
1650 (*(source + 4) ==
't') && (*(source + 5) ==
';')) {
1654 }
else if ((srclen > 5) && (*(source + 1) ==
'a') && (*(source + 2) ==
'p') && (*(source + 3) ==
'o') &&
1655 (*(source + 4) ==
's') && (*(source + 5) ==
';')) {
1660 *target++ = *source++;
1664 *target++ = *source++;
1682 char *find =
nullptr;
1683 while ((find = strpbrk(last,
"<&>\"")) !=
nullptr) {
1691 else if (symb ==
'>')
1693 else if (symb ==
'&')
1694 out->
Write(
"&");
1695 else if (symb ==
'\'')
1696 out->
Write(
"'");
1698 out->
Write(
""");
1716 out->
Put(
' ', level);
1752 out->
Write(attrname);
1754 attrname += strlen(attrname) + 1;
1783 child = child->fNext;
1787 out->
Put(
' ', level);
1827 if (commentlen < 0) {
1836 strncpy(nameptr, inp->
fCurrent, commentlen);
1837 nameptr += commentlen;
1879 const char *beg =
nullptr, *lastentity =
nullptr, *curr = contptr;
1881 while (*curr != 0) {
1882 if (!beg && (*curr ==
'&'))
1884 if (!beg || (*curr !=
';')) {
1894 lastentity = contptr;
1898 if (lastentity != beg)
1933 if (strlen(lastentity) > 0)
2140 Bool_t canhaschildren =
true;
2141 char endsymbol =
'/';
2148 canhaschildren =
false;
2159 node->
fType = nodetype;
2161 strncpy(nameptr, inp->
fCurrent, len);
2166 if (colon && parent) {
2181 if (nextsymb == endsymbol) {
2196 }
else if (nextsymb ==
'>') {
2197 if (!canhaschildren) {
2207 }
while (resvalue == 2);
2209 if (resvalue == 1) {
2230 strncpy(attrname, inp->
fCurrent, attrlen);
2231 attrname += attrlen;
2241 if ((strlen(attrname) > 6) && (strstr(attrname,
"xmlns:") == attrname)) {
2263 const char *method = is_parse_file ?
"ParseFile" :
"ParseString";
2265 case -15:
Error(method,
"Block access to external XML file at line %d", linenumber);
break;
2266 case -14:
Error(method,
"Error include external XML file at line %d", linenumber);
break;
2267 case -13:
Error(method,
"Error processing DTD part of XML file at line %d", linenumber);
break;
2268 case -12:
Error(method,
"DOCTYPE missing after <! at line %d", linenumber);
break;
2270 Error(method,
"Node cannot be closed with > symbol at line %d, for instance <?xml ... ?> node", linenumber);
2273 Error(method,
"Error in xml comments definition at line %d, must be <!-- comments -->", linenumber);
2275 case -9:
Error(method,
"Multiple namespace definitions not allowed, line %d", linenumber);
break;
2276 case -8:
Error(method,
"Invalid namespace specification, line %d", linenumber);
break;
2277 case -7:
Error(method,
"Invalid attribute value, line %d", linenumber);
break;
2278 case -6:
Error(method,
"Invalid identifier for node attribute, line %d", linenumber);
break;
2279 case -5:
Error(method,
"Mismatch between open and close nodes, line %d", linenumber);
break;
2280 case -4:
Error(method,
"Unexpected close node, line %d", linenumber);
break;
2281 case -3:
Error(method,
"Valid identifier for close node is missing, line %d", linenumber);
break;
2282 case -2:
Error(method,
"No multiple content entries allowed, line %d", linenumber);
break;
2283 case -1:
Error(method,
"Unexpected end of xml file");
break;
2284 default:
Error(method,
"XML syntax error at line %d", linenumber);
break;
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Bool_t AddRawLine(XMLNodePointer_t parent, const char *line)
Add just line into xml file Line should has correct xml syntax that later it can be decoded by xml pa...
XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent)
Allocates new xml node with specified name length.
const char * GetNSName(XMLNsPointer_t ns)
return name id of namespace
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
void SaveSingleNode(XMLNodePointer_t xmlnode, TString *res, Int_t layout=1)
convert single xmlnode (and its child node) to string if layout<=0, no any spaces or newlines will be...
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout=1)
store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
Bool_t AddComment(XMLNodePointer_t parent, const char *comment)
Adds comment line to the node.
void CleanNode(XMLNodePointer_t xmlnode)
remove all children node from xmlnode
void UnlinkNode(XMLNodePointer_t node)
unlink (detach) xmlnode from parent
void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname)
assigns dtd filename to document
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
void AddChild(XMLNodePointer_t parent, XMLNodePointer_t child)
add child element to xmlnode
Bool_t AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type="text/css", const char *title=nullptr, int alternate=-1, const char *media=nullptr, const char *charset=nullptr)
Adds style sheet definition to the specified node Creates <?xml-stylesheet alternate="yes" title="com...
XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value)
create node attribute with integer value
Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment)
add comment line to the top of the document
~TXMLEngine() override
destructor for TXMLEngine object
void AddNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
add new content of the xmlnode old content will be preserved, one could mix content with child nodes
Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name)
checks if node has attribute of specified name
char * Makestr(const char *str)
creates char* variable with copy of provided string
Bool_t IsXmlNode(XMLNodePointer_t xmlnode)
return kTRUE is this is normal xmlnode
void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level)
stream data of xmlnode to output
Bool_t IsContentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
return next attribute in the list
XMLDocPointer_t ParseStream(TXMLInputStream *input)
parses content of the stream and tries to produce xml structures
XMLNodePointer_t ReadSingleNode(const char *src)
read single xmlnode from provided string
const char * GetNSReference(XMLNsPointer_t ns)
return reference id of namespace
char * Makenstr(const char *start, int len)
creates char* variable with copy of len symbols from provided string
Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version=nullptr)
check that first node is xml processing instruction with correct xml version number
static Bool_t VerifyFilePath(const char *fname)
Checked that filename does not contains relative path below current directory.
void SetNodeContent(XMLNodePointer_t xmlnode, const char *content, Int_t len=0)
set content of the xmlnode if old node content was exists, it will be replaced
const char * GetNodeContent(XMLNodePointer_t xmlnode)
get contents (if any) of xmlnode
void DisplayError(Int_t error, Int_t linenumber, Bool_t is_parse_file=kTRUE)
Displays xml parsing error.
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
return namespace attribute (if exists)
Bool_t IsEmptyNode(XMLNodePointer_t xmlnode)
return kTRUE is this is node with special data like comments to data processing instructions
Bool_t IsCommentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
const char * GetAttrName(XMLAttrPointer_t xmlattr)
return name of the attribute
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
return first attribute in the list, namespace (if exists) will be skipped
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
Bool_t AddDocRawLine(XMLDocPointer_t xmldoc, const char *line)
Add just line on the top of xml document Line should has correct xml syntax that later it can be deco...
XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue)
Tries to construct xml node from input stream.
void FreeAttr(XMLNodePointer_t xmlnode, const char *name)
remove attribute from xmlnode
void OutputValue(char *value, TXMLOutputStream *out)
output value to output stream if symbols '<' '&' '>' '"' ''' appears in the string,...
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
returns value of attribute for xmlnode
void AddChildAfter(XMLNodePointer_t parent, XMLNodePointer_t child, XMLNodePointer_t afternode)
Insert new child node after already existing node.
Bool_t AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type="text/css", const char *title=nullptr, int alternate=-1, const char *media=nullptr, const char *charset=nullptr)
Add style sheet definition on the top of document.
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=nullptr)
create namespace attribute for xmlnode.
Bool_t fSkipComments
! if true, do not create comments nodes in document during parsing
Int_t GetIntAttr(XMLNodePointer_t node, const char *name)
returns value of attribute as integer
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname)
define if namespace of that name exists for xmlnode
void UnlinkFreeNode(XMLNodePointer_t xmlnode)
combined operation. Unlink node and free used memory
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
TXMLEngine()
default (normal) constructor of TXMLEngine class
XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode)
Allocate new attribute with specified name length and value length.
void TruncateNsExtension(XMLNodePointer_t xmlnode)
removes namespace extension of nodename
void UnpackSpecialCharacters(char *target, const char *source, int srclen)
unpack special symbols, used in xml syntax to code characters these symbols: '<' - <,...
void FreeAllAttr(XMLNodePointer_t xmlnode)
Free all attributes of the node.
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
void FreeNode(XMLNodePointer_t xmlnode)
release all memory, allocated from this node and destroys node itself
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
return value of attribute
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
return next to xmlnode node if realnode==kTRUE, any special nodes in between will be skipped
void SkipEmpty(XMLNodePointer_t &xmlnode)
Skip all current empty nodes and locate on first "true" node.
void ShiftToNext(XMLNodePointer_t &xmlnode, Bool_t realnode=kTRUE)
shifts specified node to next if realnode==kTRUE, any special nodes in between will be skipped
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
returns parent of xmlnode
void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child)
add node as first child
TXMLEntity(const TString &name, const TString &value, Bool_t sys)
Bool_t fSystem
! is system (file)
TXMLOutputStream(TString *outstr, Int_t bufsize=20000)
void OutputChar(char symb)
void Put(char symb, Int_t cnt=1)
void Write(const char *str)
TXMLOutputStream(const char *filename, Int_t bufsize=20000)
virtual ~TXMLOutputStream()
static char * Name(void *arg)
static char * Name(void *arg)