40 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(SXmlAttr_t); }
57 SXmlNode_t *fLastChild;
61 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(SXmlNode_t); }
65 SXmlNode_t *fRootNode;
70class TXMLOutputStream {
80 TXMLOutputStream(
const char *filename,
Int_t bufsize = 20000)
82 fOut =
new std::ofstream(filename);
96 fBuf = (
char *)
malloc(bufsize);
98 fMaxAddr = fBuf + bufsize;
99 fLimitAddr = fBuf +
int(bufsize * 0.75);
102 virtual ~TXMLOutputStream()
104 if (fCurrent != fBuf)
112 if (fCurrent != fBuf) {
114 fOut->write(fBuf, fCurrent - fBuf);
115 else if (fOutStr != 0)
116 fOutStr->
Append(fBuf, fCurrent - fBuf);
121 void OutputChar(
char symb)
125 else if (fOutStr != 0)
129 void Write(
const char *str)
131 int len = strlen(str);
132 if (fCurrent + len >= fMaxAddr) {
134 fOut->write(str, len);
137 *fCurrent++ = *str++;
138 if (fCurrent > fLimitAddr)
143 void Put(
char symb,
Int_t cnt = 1)
145 if (fCurrent + cnt >= fMaxAddr)
147 if (fCurrent + cnt >= fMaxAddr)
148 for (
int n = 0;
n <
cnt;
n++)
151 for (
int n = 0;
n <
cnt;
n++)
153 if (fCurrent > fLimitAddr)
159class TXMLEntity :
public TNamed {
164 Bool_t IsSystem()
const {
return fSystem; }
167class TXMLInputStream {
190 TXMLInputStream(
Bool_t isfilename,
const char *filename,
Int_t ibufsize)
191 : fInp(0), fInpStr(0), fInpStrLen(0), fBuf(0), fBufSize(0), fMaxAddr(0), fLimitAddr(0), fTotalPos(0),
192 fCurrentLine(0), fEntities(), fCurrent(0)
195 fInp =
new std::ifstream(filename);
201 fInpStrLen = filename == 0 ? 0 : strlen(filename);
205 fBuf = (
char *)
malloc(fBufSize);
210 int len = DoRead(fBuf, fBufSize);
212 fMaxAddr = fBuf + len;
213 fLimitAddr = fBuf +
int(len * 0.75);
224 virtual ~TXMLInputStream()
235 inline Bool_t EndOfFile() {
return (fInp != 0) ? fInp->eof() : (fInpStrLen <= 0); }
240 inline Bool_t EndOfStream() {
return EndOfFile() && (fCurrent >= fMaxAddr); }
245 void AddEntity(TXMLEntity *ent) { fEntities.
Add(ent); }
250 Int_t NumEntities()
const {
return fEntities.
GetLast() + 1; }
255 TXMLEntity *FindEntity(
const char *beg,
Int_t len)
260 TXMLEntity *entity = (TXMLEntity *)fEntities[
n];
261 if ((
Int_t)strlen(entity->GetName()) != len)
263 if (strncmp(beg, entity->GetName(), len) == 0)
272 int DoRead(
char *buf,
int maxsize)
279 fInp->get(buf, maxsize, 0);
280 resultsize = strlen(buf);
282 resultsize = strlcpy(buf, fInpStr, maxsize);
283 if (resultsize >= maxsize)
284 resultsize = maxsize - 1;
285 fInpStr += resultsize;
286 fInpStrLen -= resultsize;
294 Bool_t ExpandStream(
char *&curr)
299 int curlength = fMaxAddr - fBuf;
300 char *newbuf = (
char *)
realloc(fBuf, fBufSize);
304 fMaxAddr = newbuf + (fMaxAddr - fBuf);
305 fCurrent = newbuf + (fCurrent - fBuf);
306 fLimitAddr = newbuf + (fLimitAddr - fBuf);
307 curr = newbuf + (curr - fBuf);
310 int len = DoRead(fMaxAddr, fBufSize - curlength);
314 fLimitAddr +=
int(len * 0.75);
323 if (fCurrent < fLimitAddr)
327 int rest_len = fMaxAddr - fCurrent;
328 memmove(fBuf, fCurrent, rest_len);
329 int read_len = DoRead(fBuf + rest_len, fBufSize - rest_len);
332 fMaxAddr = fBuf + rest_len + read_len;
333 fLimitAddr = fBuf +
int((rest_len + read_len) * 0.75);
340 Int_t TotalPos() {
return fTotalPos; }
345 Int_t CurrentLine() {
return fCurrentLine; }
352 for (
int n = 0;
n < sz;
n++) {
355 if (fCurrent >= fLimitAddr) {
357 if (fCurrent >= fMaxAddr)
371 while (fCurrent < fMaxAddr) {
372 char symb = *fCurrent;
373 if ((symb > 26) && (symb !=
' '))
379 if (tillendl && (symb == 10))
388 Bool_t CheckFor(
const char *str)
390 int len = strlen(str);
391 char *curr = fCurrent;
392 while (curr + len > fMaxAddr) {
393 if (!ExpandStream(curr))
397 if (*str++ != *curr++)
399 return ShiftCurrent(len);
406 Int_t SearchFor(
const char *str)
408 int len = strlen(str);
410 char *curr = fCurrent;
413 while (curr + len > fMaxAddr)
414 if (!ExpandStream(curr))
416 const char *chk0 = curr;
417 const char *chk = str;
420 if (*chk++ != *chk0++) {
426 return curr - fCurrent;
435 inline Bool_t GoodStartSymbol(
unsigned char symb)
437 return (((symb >=
'a') && (symb <=
'z')) || ((symb >=
'A') && (symb <=
'Z')) || (symb ==
'_') ||
438 ((symb >= 0xc0) && (symb <= 0xd6)) || ((symb >= 0xd8) && (symb <= 0xf6)) || (symb > 0xf8));
444 Int_t LocateIdentifier()
446 unsigned char symb = (
unsigned char)*fCurrent;
448 Bool_t ok = GoodStartSymbol(symb);
452 char *curr = fCurrent;
456 if (curr >= fMaxAddr)
457 if (!ExpandStream(curr))
459 symb = (
unsigned char)*curr;
460 ok = GoodStartSymbol(symb) || ((symb >=
'0') && (symb <=
'9')) || (symb ==
':') || (symb ==
'-') ||
461 (symb ==
'.') || (symb == 0xb7);
463 return curr - fCurrent;
464 }
while (curr < fMaxAddr);
471 Int_t LocateContent()
473 char *curr = fCurrent;
474 while (curr < fMaxAddr) {
477 return curr - fCurrent;
479 if (curr >= fMaxAddr)
480 if (!ExpandStream(curr))
489 Int_t LocateValue(
unsigned curr_offset,
bool withequalsign =
true)
491 char *curr = fCurrent + curr_offset;
492 if (curr >= fMaxAddr)
493 if (!ExpandStream(curr))
499 if (curr >= fMaxAddr)
500 if (!ExpandStream(curr))
503 if ((*curr !=
'\"') && (*curr !=
'\''))
508 if (curr >= fMaxAddr)
509 if (!ExpandStream(curr))
512 return curr - (fCurrent + curr_offset) + 1;
513 }
while (curr < fMaxAddr);
538 if ((xmlnode == 0) || (
name == 0))
540 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
542 if (strcmp(SXmlAttr_t::Name(attr),
name) == 0)
556 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
558 if (strcmp(SXmlAttr_t::Name(attr),
name) == 0)
559 return SXmlAttr_t::Name(attr) + strlen(
name) + 1;
575 sscanf(attr,
"%d", &res);
588 int namelen(
name != 0 ? strlen(
name) : 0);
589 int valuelen(value != 0 ? strlen(value) : 0);
590 SXmlAttr_t *attr = (SXmlAttr_t *)
AllocateAttr(namelen, valuelen, xmlnode);
592 char *attrname = SXmlAttr_t::Name(attr);
594 strncpy(attrname,
name, namelen + 1);
597 attrname += (namelen + 1);
599 strncpy(attrname, value, valuelen + 1);
612 sprintf(sbuf,
"%d", value);
623 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
624 SXmlAttr_t *prev = 0;
626 if (strcmp(SXmlAttr_t::Name(attr),
name) == 0) {
628 prev->fNext = attr->fNext;
630 ((SXmlNode_t *)xmlnode)->fAttr = attr->fNext;
649 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
650 SXmlAttr_t *attr = node->fAttr;
652 SXmlAttr_t *next = attr->fNext;
666 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
668 SXmlAttr_t *attr = node->fAttr;
669 if ((attr != 0) && (node->fNs == attr))
694 return SXmlAttr_t::Name(xmlattr);
705 const char *attrname = SXmlAttr_t::Name(xmlattr);
706 return attrname + strlen(attrname) + 1;
714 int namelen(
name != 0 ? strlen(
name) : 0);
716 SXmlNode_t *node = (SXmlNode_t *)
AllocateNode(namelen, parent);
719 strncpy(SXmlNode_t::Name(node),
name, namelen + 1);
721 *SXmlNode_t::Name(node) = 0;
723 node->fNs = (SXmlAttr_t *)ns;
724 int contlen = (content != 0) ? strlen(content) : 0;
726 SXmlNode_t *contnode = (SXmlNode_t *)
AllocateNode(contlen, node);
728 strncpy(SXmlNode_t::Name(contnode), content, contlen + 1);
740 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
742 name = SXmlNode_t::Name(node);
743 int namelen = strlen(
name);
744 char *nsname =
new char[namelen + 7];
747 SXmlAttr_t *
first = node->fAttr;
750 SXmlAttr_t *nsattr = (SXmlAttr_t *)
NewAttr(xmlnode, 0, nsname, reference);
752 node->fAttr = nsattr;
753 nsattr->fNext =
first;
767 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
779 if ((nsname != 0) && (strncmp(nsname,
"xmlns:", 6) == 0))
798 if ((parent == 0) || (child == 0))
800 SXmlNode_t *pnode = (SXmlNode_t *)parent;
801 SXmlNode_t *cnode = (SXmlNode_t *)child;
806 cnode->fParent = pnode;
807 if (pnode->fLastChild == 0) {
808 pnode->fChild = cnode;
809 pnode->fLastChild = cnode;
813 pnode->fLastChild->fNext = cnode;
814 pnode->fLastChild = cnode;
823 if ((parent == 0) || (child == 0))
825 SXmlNode_t *pnode = (SXmlNode_t *)parent;
826 SXmlNode_t *cnode = (SXmlNode_t *)child;
831 cnode->fParent = pnode;
833 cnode->fNext = pnode->fChild;
834 pnode->fChild = cnode;
836 if (pnode->fLastChild == 0)
837 pnode->fLastChild = cnode;
845 if (afternode == 0) {
850 SXmlNode_t *pnode = (SXmlNode_t *)parent;
851 SXmlNode_t *cnode = (SXmlNode_t *)child;
852 SXmlNode_t *anode = (SXmlNode_t *)afternode;
854 if (anode->fParent != pnode) {
855 Error(
"InsertChildAfter",
"Specified afternode is not in childs list of parent node");
863 cnode->fParent = pnode;
865 cnode->fNext = anode->fNext;
866 anode->fNext = cnode;
868 if (pnode->fLastChild == anode)
869 pnode->fLastChild = cnode;
877 if ((xmlnode == 0) || (comment == 0))
880 int commentlen = strlen(comment);
882 SXmlNode_t *node = (SXmlNode_t *)
AllocateNode(commentlen, xmlnode);
884 strncpy(SXmlNode_t::Name(node), comment, commentlen + 1);
914 if ((xmlnode == 0) || (
line == 0))
917 int linelen = strlen(
line);
918 SXmlNode_t *node = (SXmlNode_t *)
AllocateNode(linelen, xmlnode);
920 strncpy(SXmlNode_t::Name(node),
line, linelen + 1);
951 int alternate,
const char *media,
const char *charset)
953 if ((xmlnode == 0) || (href == 0) || (
type == 0))
956 const char *nodename =
"xml-stylesheet";
957 int nodenamelen = strlen(nodename);
959 SXmlNode_t *node = (SXmlNode_t *)
AllocateNode(nodenamelen, xmlnode);
961 strncpy(SXmlNode_t::Name(node), nodename, nodenamelen + 1);
964 NewAttr(node, 0,
"alternate", (alternate > 0) ?
"yes" :
"no");
967 NewAttr(node, 0,
"title", title);
969 NewAttr(node, 0,
"href", href);
973 NewAttr(node, 0,
"media", media);
975 NewAttr(node, 0,
"charset", charset);
984 int alternate,
const char *media,
const char *charset)
1007 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1008 SXmlNode_t *parent = node->fParent;
1013 if (parent->fChild == node) {
1014 parent->fChild = node->fNext;
1015 if (parent->fLastChild == node)
1016 parent->fLastChild = node->fNext;
1018 SXmlNode_t *ch = parent->fChild;
1019 while (ch->fNext != node)
1021 ch->fNext = node->fNext;
1022 if (parent->fLastChild == node)
1023 parent->fLastChild = ch;
1038 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1040 SXmlNode_t *child = node->fChild;
1041 while (child != 0) {
1042 SXmlNode_t *next = child->fNext;
1047 SXmlAttr_t *attr = node->fAttr;
1049 SXmlAttr_t *next = attr->fNext;
1074 return xmlnode == 0 ? 0 : SXmlNode_t::Name(xmlnode);
1084 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1085 if (node->fChild == 0)
1091 return SXmlNode_t::Name(node->fChild);
1102 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1103 if ((node->fChild != 0) && (node->fChild->fType ==
kXML_CONTENT))
1109 len = strlen(content);
1111 SXmlNode_t *contnode = (SXmlNode_t *)
AllocateNode(len, 0);
1112 char *nameptr = SXmlNode_t::Name(contnode);
1114 strncpy(nameptr, content, len);
1127 if ((xmlnode == 0) || (content == 0))
1130 len = strlen(content);
1132 SXmlNode_t *contnode = (SXmlNode_t *)
AllocateNode(len, xmlnode);
1133 char *nameptr = SXmlNode_t::Name(contnode);
1135 strncpy(nameptr, content, len);
1147 if (realnode && (res != 0) && (((SXmlNode_t *)res)->fType !=
kXML_NODE))
1157 return xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fParent;
1167 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1168 if ((xmlnode == 0) || !realnode)
1170 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1182 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1183 if ((xmlnode == 0) || !realnode)
1185 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1193 return xmlnode == 0 ?
kFALSE : (((SXmlNode_t *)xmlnode)->fType ==
kXML_NODE);
1201 return xmlnode == 0 ?
kTRUE : (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1236 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1238 SXmlNode_t *child = node->fChild;
1239 while (child != 0) {
1240 SXmlNode_t *next = child->fNext;
1246 node->fLastChild = 0;
1254 SXmlDoc_t *doc =
new SXmlDoc_t;
1255 doc->fRootNode = (SXmlNode_t *)
NewChild(0, 0,
"??DummyTopNode??", 0);
1260 NewAttr(vernode, 0,
"version", version);
1275 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1276 delete[] doc->fDtdName;
1277 doc->fDtdName =
Makestr(dtdname);
1278 delete[] doc->fDtdRoot;
1279 doc->fDtdRoot =
Makestr(rootname);
1289 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1291 delete[] doc->fDtdName;
1292 delete[] doc->fDtdRoot;
1308 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1310 TXMLOutputStream out(filename, 100000);
1317 }
while (child != 0);
1355 if ((filename == 0) || (strlen(filename) == 0))
1357 if (maxbuf < 100000)
1359 TXMLInputStream inp(
true, filename, maxbuf);
1368 if ((xmlstring == 0) || (strlen(xmlstring) == 0))
1370 TXMLInputStream inp(
false, xmlstring, 100000);
1389 ReadNode(((SXmlDoc_t *)xmldoc)->fRootNode, inp, resvalue);
1396 if (!inp->EndOfStream())
1399 if (inp->EndOfStream()) {
1431 const char *value =
GetAttr(vernode,
"version");
1437 return strcmp(version, value) == 0;
1449 if ((res == 0) || (xmlnode == 0))
1452 TXMLOutputStream out(res, 10000);
1454 SaveNode(xmlnode, &out, layout, 0);
1465 TXMLInputStream inp(
false, src, 10000);
1471 if (resvalue <= 0) {
1487 int len = strlen(str);
1490 char *res =
new char[len + 1];
1491 strncpy(res, str, len + 1);
1500 if ((str == 0) || (len == 0))
1502 char *res =
new char[len + 1];
1503 strncpy(res, str, len);
1515 SXmlNode_t *node = (SXmlNode_t *)
malloc(
sizeof(SXmlNode_t) + namelen + 1);
1522 node->fLastChild = 0;
1538 SXmlAttr_t *attr = (SXmlAttr_t *)
malloc(
sizeof(SXmlAttr_t) + namelen + 1 + valuelen + 1);
1540 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1544 if (node->fAttr == 0)
1547 SXmlAttr_t *
d = node->fAttr;
1548 while (
d->fNext != 0)
1561 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1563 if (node->fNs != 0) {
1564 const char *nsname = SXmlAttr_t::Name(node->fNs) + 6;
1565 if (strcmp(nsname,
name) == 0)
1568 node = node->fParent;
1578 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1581 char *colon = strchr(SXmlNode_t::Name(node),
':');
1585 char *copyname = SXmlNode_t::Name(node);
1588 *(copyname++) = *(++colon);
1597 while (srclen > 0) {
1598 if (*source ==
'&') {
1599 if ((srclen > 3) && (*(source + 1) ==
'l') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1603 }
else if ((srclen > 3) && (*(source + 1) ==
'g') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1607 }
else if ((srclen > 4) && (*(source + 1) ==
'a') && (*(source + 2) ==
'm') && (*(source + 3) ==
'p') &&
1608 (*(source + 4) ==
';')) {
1612 }
else if ((srclen > 5) && (*(source + 1) ==
'q') && (*(source + 2) ==
'u') && (*(source + 3) ==
'o') &&
1613 (*(source + 4) ==
't') && (*(source + 5) ==
';')) {
1617 }
else if ((srclen > 5) && (*(source + 1) ==
'a') && (*(source + 2) ==
'p') && (*(source + 3) ==
'o') &&
1618 (*(source + 4) ==
's') && (*(source + 5) ==
';')) {
1623 *target++ = *source++;
1627 *target++ = *source++;
1646 while ((find = strpbrk(last,
"<&>\"")) != 0) {
1654 else if (symb ==
'>')
1656 else if (symb ==
'&')
1657 out->Write(
"&");
1658 else if (symb ==
'\'')
1659 out->Write(
"'");
1661 out->Write(
""");
1674 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1676 Bool_t issingleline = (node->fChild == 0);
1679 out->Put(
' ', level);
1683 out->Write(SXmlNode_t::Name(node));
1689 out->Write(SXmlNode_t::Name(node));
1694 out->Write(SXmlNode_t::Name(node));
1705 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1706 out->Write(SXmlAttr_t::Name(node->fNs) + 6);
1709 out->Write(SXmlNode_t::Name(node));
1711 SXmlAttr_t *attr = node->fAttr;
1714 char *attrname = SXmlAttr_t::Name(attr);
1715 out->Write(attrname);
1717 attrname += strlen(attrname) + 1;
1736 SXmlNode_t *child = node->fChild;
1738 if ((child != 0) && (child->fType ==
kXML_CONTENT) && (child->fNext == 0)) {
1740 out->Write(SXmlNode_t::Name(child));
1744 while (child != 0) {
1746 child = child->fNext;
1750 out->Put(
' ', level);
1755 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1756 out->Write(SXmlAttr_t::Name(node->fNs) + 6);
1759 out->Write(SXmlNode_t::Name(node));
1778 if (!inp->SkipSpaces()) {
1782 SXmlNode_t *parent = (SXmlNode_t *)xmlparent;
1784 SXmlNode_t *node = 0;
1787 while (inp->CheckFor(
"<!--")) {
1788 Int_t commentlen = inp->SearchFor(
"-->");
1789 if (commentlen < 0) {
1795 node = (SXmlNode_t *)
AllocateNode(commentlen, xmlparent);
1796 char *nameptr = SXmlNode_t::Name(node);
1798 strncpy(nameptr, inp->fCurrent, commentlen);
1799 nameptr += commentlen;
1803 if (!inp->ShiftCurrent(commentlen + 3)) {
1807 if (!inp->SkipSpaces() && !inp->EndOfStream()) {
1816 if (*inp->fCurrent !=
'<') {
1823 int contlen = inp->LocateContent();
1827 SXmlNode_t *contnode = (SXmlNode_t *)
AllocateNode(contlen, xmlparent);
1829 char *contptr = SXmlNode_t::Name(contnode);
1831 if (!inp->ShiftCurrent(contlen))
1834 if (inp->NumEntities() <= 0) {
1841 const char *beg(0), *lastentity(0), *curr(contptr);
1843 while (*curr != 0) {
1844 if ((beg == 0) && (*curr ==
'&'))
1846 if ((beg == 0) || (*curr !=
';')) {
1851 TXMLEntity *entity = inp->FindEntity(beg + 1, curr - beg - 1);
1855 if (lastentity == 0) {
1856 lastentity = contptr;
1860 if (lastentity != beg)
1863 if (entity->IsSystem()) {
1865 if (entitydoc == 0) {
1872 while (topnode != 0) {
1889 if (lastentity != 0) {
1891 if (strlen(lastentity) > 0)
1902 if (!inp->ShiftCurrent())
1906 if (*inp->fCurrent ==
'/') {
1908 if (!inp->ShiftCurrent())
1910 if (!inp->SkipSpaces())
1912 Int_t len = inp->LocateIdentifier();
1923 if (strncmp(SXmlNode_t::Name(parent), inp->fCurrent, len) != 0) {
1928 if (!inp->ShiftCurrent(len))
1931 if (!inp->SkipSpaces())
1933 if (*inp->fCurrent !=
'>')
1935 if (!inp->ShiftCurrent())
1938 if (parent->fNs != 0)
1941 inp->SkipSpaces(
kTRUE);
1946 if (*inp->fCurrent ==
'!') {
1948 if (!inp->ShiftCurrent())
1950 if (!inp->CheckFor(
"DOCTYPE")) {
1954 if (!inp->SkipSpaces()) {
1960 Int_t len = inp->LocateIdentifier();
1965 if (!inp->ShiftCurrent(len)) {
1969 if (!inp->SkipSpaces()) {
1975 if (inp->CheckFor(
"[")) {
1976 if (!inp->SkipSpaces())
1979 if (inp->CheckFor(
"<!ENTITY")) {
1981 if (!inp->SkipSpaces()) {
1985 Int_t namelen = inp->LocateIdentifier();
1990 TString entity_name(inp->fCurrent, namelen);
1991 if (!inp->ShiftCurrent(namelen)) {
1995 if (!inp->SkipSpaces()) {
2000 if (inp->CheckFor(
"SYSTEM")) {
2001 if (!inp->SkipSpaces()) {
2008 Int_t valuelen = inp->LocateValue(0,
false);
2014 TString entity_value(inp->fCurrent + 1, valuelen - 2);
2016 if (!inp->ShiftCurrent(valuelen)) {
2021 if (*inp->fCurrent !=
'>') {
2025 if (!inp->ShiftCurrent()) {
2031 inp->AddEntity(
new TXMLEntity(entity_name, entity_value, is_system));
2035 if (inp->CheckFor(
"<!ELEMENT")) {
2037 if (!inp->SkipSpaces()) {
2041 Int_t namelen = inp->LocateIdentifier();
2047 if (!inp->ShiftCurrent(namelen)) {
2051 if (!inp->SkipSpaces()) {
2056 if (!inp->CheckFor(
"(")) {
2060 if (inp->SearchFor(
")") <= 0) {
2066 if (*inp->fCurrent !=
'>') {
2070 if (!inp->ShiftCurrent()) {
2082 if (!inp->CheckFor(
"]")) {
2088 if (!inp->CheckFor(
">")) {
2098 Bool_t canhaschildren =
true;
2099 char endsymbol =
'/';
2102 if (*inp->fCurrent ==
'?') {
2103 if (!inp->ShiftCurrent())
2106 canhaschildren =
false;
2110 if (!inp->SkipSpaces())
2112 Int_t len = inp->LocateIdentifier();
2116 char *nameptr = SXmlNode_t::Name(node);
2117 node->fType = nodetype;
2119 strncpy(nameptr, inp->fCurrent, len);
2123 char *colon = strchr(SXmlNode_t::Name(node),
':');
2124 if ((colon != 0) && (parent != 0)) {
2126 node->fNs = (SXmlAttr_t *)
FindNs(xmlparent, SXmlNode_t::Name(node));
2130 if (!inp->ShiftCurrent(len))
2134 if (!inp->SkipSpaces())
2137 char nextsymb = *inp->fCurrent;
2139 if (nextsymb == endsymbol) {
2140 if (!inp->ShiftCurrent())
2142 if (*inp->fCurrent ==
'>') {
2143 if (!inp->ShiftCurrent())
2149 inp->SkipSpaces(
kTRUE);
2154 }
else if (nextsymb ==
'>') {
2155 if (!canhaschildren) {
2160 if (!inp->ShiftCurrent())
2165 }
while (resvalue == 2);
2167 if (resvalue == 1) {
2173 Int_t attrlen = inp->LocateIdentifier();
2179 int valuelen = inp->LocateValue(attrlen,
true);
2187 char *attrname = SXmlAttr_t::Name(attr);
2188 strncpy(attrname, inp->fCurrent, attrlen);
2189 attrname += attrlen;
2194 if (!inp->ShiftCurrent(attrlen + valuelen))
2197 attrname = SXmlAttr_t::Name(attr);
2199 if ((strlen(attrname) > 6) && (strstr(attrname,
"xmlns:") == attrname)) {
2200 if (strcmp(SXmlNode_t::Name(node), attrname + 6) != 0) {
2204 if (node->fNs != 0) {
2222 case -14:
Error(
"ParseFile",
"Error include external XML file at line %d", linenumber);
break;
2223 case -13:
Error(
"ParseFile",
"Error processing DTD part of XML file at line %d", linenumber);
break;
2224 case -12:
Error(
"ParseFile",
"DOCTYPE missing after <! at line %d", linenumber);
break;
2226 Error(
"ParseFile",
"Node cannot be closed with > symbol at line %d, for instance <?xml ... ?> node", linenumber);
2229 Error(
"ParseFile",
"Error in xml comments definition at line %d, must be <!-- comments -->", linenumber);
2231 case -9:
Error(
"ParseFile",
"Multiple namespace definitions not allowed, line %d", linenumber);
break;
2232 case -8:
Error(
"ParseFile",
"Invalid namespace specification, line %d", linenumber);
break;
2233 case -7:
Error(
"ParseFile",
"Invalid attribute value, line %d", linenumber);
break;
2234 case -6:
Error(
"ParseFile",
"Invalid identifier for node attribute, line %d", linenumber);
break;
2235 case -5:
Error(
"ParseFile",
"Mismatch between open and close nodes, line %d", linenumber);
break;
2236 case -4:
Error(
"ParseFile",
"Unexpected close node, line %d", linenumber);
break;
2237 case -3:
Error(
"ParseFile",
"Valid identifier for close node is missing, line %d", linenumber);
break;
2238 case -2:
Error(
"ParseFile",
"No multiple content entries allowed, line %d", linenumber);
break;
2239 case -1:
Error(
"ParseFile",
"Unexpected end of xml file");
break;
2240 default:
Error(
"ParseFile",
"XML syntax error at line %d", linenumber);
break;
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
The TNamed class is the base class for all named ROOT classes.
Int_t GetLast() const
Return index of last object in array.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TString & Append(const char *cs)
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...
void DisplayError(Int_t error, Int_t linenumber)
Displays xml parsing error.
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
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
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
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.
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()
if true, do not create comments nodes in document during parsing
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.
virtual ~TXMLEngine()
destructor for TXMLEngine object
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
void Init(TClassEdit::TInterpreterLookupHelper *helper)