37 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(SXmlAttr_t); }
54 SXmlNode_t *fLastChild;
58 static inline char *
Name(
void *arg) {
return (
char *)arg +
sizeof(SXmlNode_t); }
62 SXmlNode_t *fRootNode;
67 class TXMLOutputStream {
77 TXMLOutputStream(
const char *filename,
Int_t bufsize = 20000)
79 fOut =
new std::ofstream(filename);
93 fBuf = (
char *)
malloc(bufsize);
95 fMaxAddr = fBuf + bufsize;
96 fLimitAddr = fBuf + int(bufsize * 0.75);
99 virtual ~TXMLOutputStream()
101 if (fCurrent != fBuf)
109 if (fCurrent != fBuf) {
111 fOut->write(fBuf, fCurrent - fBuf);
112 else if (fOutStr != 0)
113 fOutStr->
Append(fBuf, fCurrent - fBuf);
118 void OutputChar(
char symb)
122 else if (fOutStr != 0)
126 void Write(
const char *str)
128 int len = strlen(str);
129 if (fCurrent + len >= fMaxAddr) {
131 fOut->write(str, len);
134 *fCurrent++ = *str++;
135 if (fCurrent > fLimitAddr)
142 if (fCurrent +
cnt >= fMaxAddr)
144 if (fCurrent +
cnt >= fMaxAddr)
145 for (
int n = 0;
n <
cnt;
n++)
148 for (
int n = 0;
n <
cnt;
n++)
150 if (fCurrent > fLimitAddr)
156 class TXMLEntity :
public TNamed {
161 Bool_t IsSystem()
const {
return fSystem; }
164 class TXMLInputStream {
187 TXMLInputStream(
Bool_t isfilename,
const char *filename,
Int_t ibufsize)
188 : fInp(0), fInpStr(0), fInpStrLen(0), fBuf(0), fBufSize(0), fMaxAddr(0), fLimitAddr(0), fTotalPos(0),
189 fCurrentLine(0), fEntities(), fCurrent(0)
192 fInp =
new std::ifstream(filename);
198 fInpStrLen = filename == 0 ? 0 : strlen(filename);
202 fBuf = (
char *)
malloc(fBufSize);
207 int len = DoRead(fBuf, fBufSize);
209 fMaxAddr = fBuf + len;
210 fLimitAddr = fBuf + int(len * 0.75);
221 virtual ~TXMLInputStream()
232 inline Bool_t EndOfFile() {
return (fInp != 0) ? fInp->eof() : (fInpStrLen <= 0); }
237 inline Bool_t EndOfStream() {
return EndOfFile() && (fCurrent >= fMaxAddr); }
242 void AddEntity(TXMLEntity *ent) { fEntities.
Add(ent); }
247 Int_t NumEntities()
const {
return fEntities.
GetLast() + 1; }
252 TXMLEntity *FindEntity(
const char *beg,
Int_t len)
257 TXMLEntity *entity = (TXMLEntity *)fEntities[
n];
258 if ((
Int_t)strlen(entity->GetName()) != len)
260 if (strncmp(beg, entity->GetName(), len) == 0)
269 int DoRead(
char *buf,
int maxsize)
274 fInp->get(buf, maxsize, 0);
275 maxsize = strlen(buf);
277 if (maxsize > fInpStrLen)
278 maxsize = fInpStrLen;
279 strncpy(buf, fInpStr, maxsize);
281 fInpStrLen -= maxsize;
289 Bool_t ExpandStream(
char *&curr)
294 int curlength = fMaxAddr - fBuf;
295 char *newbuf = (
char *)
realloc(fBuf, fBufSize);
299 fMaxAddr = newbuf + (fMaxAddr - fBuf);
300 fCurrent = newbuf + (fCurrent - fBuf);
301 fLimitAddr = newbuf + (fLimitAddr - fBuf);
302 curr = newbuf + (curr - fBuf);
305 int len = DoRead(fMaxAddr, fBufSize - curlength);
309 fLimitAddr += int(len * 0.75);
318 if (fCurrent < fLimitAddr)
322 int rest_len = fMaxAddr - fCurrent;
323 memmove(fBuf, fCurrent, rest_len);
324 int read_len = DoRead(fBuf + rest_len, fBufSize - rest_len);
327 fMaxAddr = fBuf + rest_len + read_len;
328 fLimitAddr = fBuf + int((rest_len + read_len) * 0.75);
335 Int_t TotalPos() {
return fTotalPos; }
340 Int_t CurrentLine() {
return fCurrentLine; }
347 for (
int n = 0;
n < sz;
n++) {
350 if (fCurrent >= fLimitAddr) {
352 if (fCurrent >= fMaxAddr)
366 while (fCurrent < fMaxAddr) {
367 char symb = *fCurrent;
368 if ((symb > 26) && (symb !=
' '))
374 if (tillendl && (symb == 10))
383 Bool_t CheckFor(
const char *str)
385 int len = strlen(str);
386 char *curr = fCurrent;
387 while (curr + len > fMaxAddr) {
388 if (!ExpandStream(curr))
392 if (*str++ != *curr++)
394 return ShiftCurrent(len);
401 Int_t SearchFor(
const char *str)
403 int len = strlen(str);
405 char *curr = fCurrent;
409 while (curr + len > fMaxAddr)
410 if (!ExpandStream(curr))
413 const char *chk = str;
416 if (*chk++ != *chk0++) {
422 return curr - fCurrent;
423 }
while (curr < fMaxAddr);
430 inline Bool_t GoodStartSymbol(
unsigned char symb)
432 return (((symb >=
'a') && (symb <=
'z')) || ((symb >=
'A') && (symb <=
'Z')) || (symb ==
'_') ||
433 ((symb >= 0xc0) && (symb <= 0xd6)) || ((symb >= 0xd8) && (symb <= 0xf6)) || (symb > 0xf8));
439 Int_t LocateIdentifier()
441 unsigned char symb = (
unsigned char)*fCurrent;
443 Bool_t ok = GoodStartSymbol(symb);
447 char *curr = fCurrent;
451 if (curr >= fMaxAddr)
452 if (!ExpandStream(curr))
454 symb = (
unsigned char)*curr;
455 ok = GoodStartSymbol(symb) || ((symb >=
'0') && (symb <=
'9')) || (symb ==
':') || (symb ==
'-') ||
456 (symb ==
'.') || (symb == 0xb7);
458 return curr - fCurrent;
459 }
while (curr < fMaxAddr);
466 Int_t LocateContent()
468 char *curr = fCurrent;
469 while (curr < fMaxAddr) {
472 return curr - fCurrent;
474 if (curr >= fMaxAddr)
475 if (!ExpandStream(curr))
484 Int_t LocateValue(
unsigned curr_offset,
bool withequalsign =
true)
486 char *curr = fCurrent + curr_offset;
487 if (curr >= fMaxAddr)
488 if (!ExpandStream(curr))
494 if (curr >= fMaxAddr)
495 if (!ExpandStream(curr))
498 if ((*curr !=
'\"') && (*curr !=
'\''))
503 if (curr >= fMaxAddr)
504 if (!ExpandStream(curr))
507 return curr - (fCurrent + curr_offset) + 1;
508 }
while (curr < fMaxAddr);
533 if ((xmlnode == 0) || (name == 0))
535 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
551 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
568 const char *attr = GetAttr(xmlnode, name);
570 sscanf(attr,
"%d", &res);
583 int namelen(name != 0 ? strlen(name) : 0);
584 int valuelen(value != 0 ? strlen(value) : 0);
585 SXmlAttr_t *attr = (SXmlAttr_t *)AllocateAttr(namelen, valuelen, xmlnode);
589 strncpy(attrname, name, namelen + 1);
592 attrname += (namelen + 1);
594 strncpy(attrname, value, valuelen + 1);
607 sprintf(sbuf,
"%d", value);
608 return NewAttr(xmlnode, 0, name, sbuf);
618 SXmlAttr_t *attr = ((SXmlNode_t *)xmlnode)->fAttr;
619 SXmlAttr_t *prev = 0;
623 prev->fNext = attr->fNext;
625 ((SXmlNode_t *)xmlnode)->fAttr = attr->fNext;
644 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
645 SXmlAttr_t *attr = node->fAttr;
647 SXmlAttr_t *next = attr->fNext;
661 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
663 SXmlAttr_t *attr = node->fAttr;
664 if ((attr != 0) && (node->fNs == attr))
701 return attrname + strlen(attrname) + 1;
709 int namelen(name != 0 ? strlen(name) : 0);
711 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(namelen, parent);
718 node->fNs = (SXmlAttr_t *)ns;
719 int contlen = (content != 0) ? strlen(content) : 0;
721 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(contlen, node);
735 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
738 int namelen = strlen(name);
739 char *nsname =
new char[namelen + 7];
740 snprintf(nsname, namelen + 7,
"xmlns:%s", name);
742 SXmlAttr_t *
first = node->fAttr;
745 SXmlAttr_t *nsattr = (SXmlAttr_t *)NewAttr(xmlnode, 0, nsname, reference);
747 node->fAttr = nsattr;
748 nsattr->fNext = first;
762 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
774 if ((nsname != 0) && (strncmp(nsname,
"xmlns:", 6) == 0))
793 if ((parent == 0) || (child == 0))
795 SXmlNode_t *pnode = (SXmlNode_t *)parent;
796 SXmlNode_t *cnode = (SXmlNode_t *)child;
797 cnode->fParent = pnode;
798 if (pnode->fLastChild == 0) {
799 pnode->fChild = cnode;
800 pnode->fLastChild = cnode;
804 pnode->fLastChild->fNext = cnode;
805 pnode->fLastChild = cnode;
814 if ((parent == 0) || (child == 0))
816 SXmlNode_t *pnode = (SXmlNode_t *)parent;
817 SXmlNode_t *cnode = (SXmlNode_t *)child;
818 cnode->fParent = pnode;
820 cnode->fNext = pnode->fChild;
821 pnode->fChild = cnode;
823 if (pnode->fLastChild == 0)
824 pnode->fLastChild = cnode;
832 if ((xmlnode == 0) || (comment == 0))
835 int commentlen = strlen(comment);
837 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(commentlen, xmlnode);
853 UnlinkNode(rootnode);
855 Bool_t res = AddComment(((SXmlDoc_t *)xmldoc)->fRootNode, comment);
869 if ((xmlnode == 0) || (line == 0))
872 int linelen = strlen(line);
873 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(linelen, xmlnode);
887 UnlinkNode(rootnode);
889 Bool_t res = AddRawLine(((SXmlDoc_t *)xmldoc)->fRootNode, line);
906 int alternate,
const char *media,
const char *charset)
908 if ((xmlnode == 0) || (href == 0) || (type == 0))
911 const char *nodename =
"xml-stylesheet";
912 int nodenamelen = strlen(nodename);
914 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(nodenamelen, xmlnode);
919 NewAttr(node, 0,
"alternate", (alternate > 0) ?
"yes" :
"no");
922 NewAttr(node, 0,
"title", title);
924 NewAttr(node, 0,
"href", href);
925 NewAttr(node, 0,
"type", type);
928 NewAttr(node, 0,
"media", media);
930 NewAttr(node, 0,
"charset", charset);
939 int alternate,
const char *media,
const char *charset)
945 UnlinkNode(rootnode);
947 Bool_t res = AddStyleSheet(((SXmlDoc_t *)xmldoc)->fRootNode, href, type, title, alternate, media, charset);
961 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
963 SXmlNode_t *parent = node->fParent;
968 if (parent->fChild == node) {
969 parent->fChild = node->fNext;
970 if (parent->fLastChild == node)
971 parent->fLastChild = node->fNext;
973 SXmlNode_t *ch = parent->fChild;
974 while (ch->fNext != node)
976 ch->fNext = node->fNext;
977 if (parent->fLastChild == node)
978 parent->fLastChild = ch;
990 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
992 SXmlNode_t *child = node->fChild;
994 SXmlNode_t *next = child->fNext;
999 SXmlAttr_t *attr = node->fAttr;
1001 SXmlAttr_t *next = attr->fNext;
1017 UnlinkNode(xmlnode);
1036 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1037 if (node->fChild == 0)
1054 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1055 if ((node->fChild != 0) && (node->fChild->fType ==
kXML_CONTENT))
1061 len = strlen(content);
1063 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(len, 0);
1066 strncpy(nameptr, content, len);
1079 if ((xmlnode == 0) || (content == 0))
1082 len = strlen(content);
1084 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(len, xmlnode);
1087 strncpy(nameptr, content, len);
1099 if (realnode && (res != 0) && (((SXmlNode_t *)res)->fType !=
kXML_NODE))
1100 ShiftToNext(res,
kTRUE);
1109 return xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fParent;
1119 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1120 if ((xmlnode == 0) || !realnode)
1122 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1134 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1135 if ((xmlnode == 0) || !realnode)
1137 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1145 return xmlnode == 0 ?
kFALSE : (((SXmlNode_t *)xmlnode)->fType ==
kXML_NODE);
1153 return xmlnode == 0 ?
kTRUE : (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1177 if (IsEmptyNode(xmlnode))
1178 ShiftToNext(xmlnode);
1188 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1190 SXmlNode_t *child = node->fChild;
1191 while (child != 0) {
1192 SXmlNode_t *next = child->fNext;
1198 node->fLastChild = 0;
1206 SXmlDoc_t *doc =
new SXmlDoc_t;
1207 doc->fRootNode = (SXmlNode_t *)NewChild(0, 0,
"??DummyTopNode??", 0);
1212 NewAttr(vernode, 0,
"version", version);
1227 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1228 delete[] doc->fDtdName;
1229 doc->fDtdName = Makestr(dtdname);
1230 delete[] doc->fDtdRoot;
1231 doc->fDtdRoot = Makestr(rootname);
1241 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1243 delete[] doc->fDtdName;
1244 delete[] doc->fDtdRoot;
1260 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1262 TXMLOutputStream out(filename, 100000);
1267 SaveNode(child, &out, layout, 0);
1268 ShiftToNext(child,
kFALSE);
1269 }
while (child != 0);
1280 FreeNode(DocGetRootElement(xmldoc));
1297 return GetChild(xmlnode,
kTRUE);
1307 if ((filename == 0) || (strlen(filename) == 0))
1309 if (maxbuf < 100000)
1311 TXMLInputStream inp(
true, filename, maxbuf);
1312 return ParseStream(&inp);
1320 if ((xmlstring == 0) || (strlen(xmlstring) == 0))
1322 TXMLInputStream inp(
false, xmlstring, 2 * strlen(xmlstring));
1323 return ParseStream(&inp);
1341 ReadNode(((SXmlDoc_t *)xmldoc)->fRootNode, inp, resvalue);
1348 if (!inp->EndOfStream())
1351 if (inp->EndOfStream()) {
1358 DisplayError(resvalue, inp->CurrentLine());
1380 if (strcmp(GetNodeName(vernode),
"xml") != 0)
1383 const char *value = GetAttr(vernode,
"version");
1389 return strcmp(version, value) == 0;
1401 if ((res == 0) || (xmlnode == 0))
1404 TXMLOutputStream out(res, 10000);
1406 SaveNode(xmlnode, &out, layout, 0);
1417 TXMLInputStream inp(
false, src, 10000);
1423 if (resvalue <= 0) {
1424 DisplayError(resvalue, inp.CurrentLine());
1439 int len = strlen(str);
1442 char *res =
new char[len + 1];
1443 strncpy(res, str, len + 1);
1452 if ((str == 0) || (len == 0))
1454 char *res =
new char[len + 1];
1455 strncpy(res, str, len);
1467 SXmlNode_t *node = (SXmlNode_t *)
malloc(
sizeof(SXmlNode_t) + namelen + 1);
1474 node->fLastChild = 0;
1490 SXmlAttr_t *attr = (SXmlAttr_t *)
malloc(
sizeof(SXmlAttr_t) + namelen + 1 + valuelen + 1);
1492 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1496 if (node->fAttr == 0)
1499 SXmlAttr_t *d = node->fAttr;
1500 while (d->fNext != 0)
1513 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1515 if (node->fNs != 0) {
1517 if (strcmp(nsname, name) == 0)
1520 node = node->fParent;
1530 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1540 *(copyname++) = *(++colon);
1549 while (srclen > 0) {
1550 if (*source ==
'&') {
1551 if ((srclen > 3) && (*(source + 1) ==
'l') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1555 }
else if ((srclen > 3) && (*(source + 1) ==
'g') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1559 }
else if ((srclen > 4) && (*(source + 1) ==
'a') && (*(source + 2) ==
'm') && (*(source + 3) ==
'p') &&
1560 (*(source + 4) ==
';')) {
1564 }
else if ((srclen > 5) && (*(source + 1) ==
'q') && (*(source + 2) ==
'u') && (*(source + 3) ==
'o') &&
1565 (*(source + 4) ==
't') && (*(source + 5) ==
';')) {
1569 }
else if ((srclen > 5) && (*(source + 1) ==
'a') && (*(source + 2) ==
'p') && (*(source + 3) ==
'o') &&
1570 (*(source + 4) ==
's') && (*(source + 5) ==
';')) {
1575 *target++ = *source++;
1579 *target++ = *source++;
1598 while ((find = strpbrk(last,
"<&>\"")) != 0) {
1606 else if (symb ==
'>')
1608 else if (symb ==
'&')
1609 out->Write(
"&");
1610 else if (symb ==
'\'')
1611 out->Write(
"'");
1613 out->Write(
""");
1626 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1628 Bool_t issingleline = (node->fChild == 0);
1631 out->Put(
' ', level);
1657 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1663 SXmlAttr_t *attr = node->fAttr;
1667 out->Write(attrname);
1669 attrname += strlen(attrname) + 1;
1670 OutputValue(attrname, out);
1688 SXmlNode_t *child = node->fChild;
1690 if ((child != 0) && (child->fType ==
kXML_CONTENT) && (child->fNext == 0)) {
1696 while (child != 0) {
1698 child = child->fNext;
1702 out->Put(
' ', level);
1707 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1730 if (!inp->SkipSpaces()) {
1734 SXmlNode_t *parent = (SXmlNode_t *)xmlparent;
1736 SXmlNode_t *node = 0;
1739 while (inp->CheckFor(
"<!--")) {
1740 Int_t commentlen = inp->SearchFor(
"-->");
1741 if (commentlen <= 0) {
1746 if (!fSkipComments) {
1747 node = (SXmlNode_t *)AllocateNode(commentlen, xmlparent);
1750 strncpy(nameptr, inp->fCurrent, commentlen);
1751 nameptr += commentlen;
1755 if (!inp->ShiftCurrent(commentlen + 3)) {
1759 if (!inp->SkipSpaces() && !inp->EndOfStream()) {
1768 if (*inp->fCurrent !=
'<') {
1775 int contlen = inp->LocateContent();
1779 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(contlen, xmlparent);
1782 UnpackSpecialCharacters(contptr, inp->fCurrent, contlen);
1783 if (!inp->ShiftCurrent(contlen))
1786 if (inp->NumEntities() <= 0) {
1793 const char *beg(0), *lastentity(0), *curr(contptr);
1795 while (*curr != 0) {
1796 if ((beg == 0) && (*curr ==
'&'))
1798 if ((beg == 0) || (*curr !=
';')) {
1803 TXMLEntity *entity = inp->FindEntity(beg + 1, curr - beg - 1);
1807 if (lastentity == 0) {
1808 lastentity = contptr;
1809 UnlinkNode(contnode);
1812 if (lastentity != beg)
1813 AddNodeContent(xmlparent, lastentity, beg - lastentity);
1816 if (entity->IsSystem()) {
1818 if (entitydoc == 0) {
1825 while (topnode != 0) {
1827 ShiftToNext(topnode,
false);
1828 UnlinkNode(currnode);
1829 AddChild(xmlparent, currnode);
1832 AddNodeContent(xmlparent, entity->GetTitle());
1842 if (lastentity != 0) {
1844 if (strlen(lastentity) > 0)
1845 AddNodeContent(xmlparent, lastentity);
1855 if (!inp->ShiftCurrent())
1859 if (*inp->fCurrent ==
'/') {
1861 if (!inp->ShiftCurrent())
1863 if (!inp->SkipSpaces())
1865 Int_t len = inp->LocateIdentifier();
1881 if (!inp->ShiftCurrent(len))
1884 if (!inp->SkipSpaces())
1886 if (*inp->fCurrent !=
'>')
1888 if (!inp->ShiftCurrent())
1891 if (parent->fNs != 0)
1894 inp->SkipSpaces(
kTRUE);
1899 if (*inp->fCurrent ==
'!') {
1901 if (!inp->ShiftCurrent())
1903 if (!inp->CheckFor(
"DOCTYPE")) {
1907 if (!inp->SkipSpaces()) {
1913 Int_t len = inp->LocateIdentifier();
1918 if (!inp->ShiftCurrent(len)) {
1922 if (!inp->SkipSpaces()) {
1928 if (inp->CheckFor(
"[")) {
1929 if (!inp->SkipSpaces())
1932 if (inp->CheckFor(
"<!ENTITY")) {
1934 if (!inp->SkipSpaces()) {
1938 Int_t namelen = inp->LocateIdentifier();
1943 TString entity_name(inp->fCurrent, namelen);
1944 if (!inp->ShiftCurrent(namelen)) {
1948 if (!inp->SkipSpaces()) {
1953 if (inp->CheckFor(
"SYSTEM")) {
1954 if (!inp->SkipSpaces()) {
1961 Int_t valuelen = inp->LocateValue(0,
false);
1967 TString entity_value(inp->fCurrent + 1, valuelen - 2);
1969 if (!inp->ShiftCurrent(valuelen)) {
1974 if (*inp->fCurrent !=
'>') {
1978 if (!inp->ShiftCurrent()) {
1984 inp->AddEntity(
new TXMLEntity(entity_name, entity_value, is_system));
1991 if (inp->CheckFor(
"<!ELEMENT")) {
1993 if (!inp->SkipSpaces()) {
1997 Int_t namelen = inp->LocateIdentifier();
2003 if (!inp->ShiftCurrent(namelen)) {
2007 if (!inp->SkipSpaces()) {
2012 if (!inp->CheckFor(
"(")) {
2016 if (inp->SearchFor(
")") <= 0) {
2022 if (*inp->fCurrent !=
'>') {
2026 if (!inp->ShiftCurrent()) {
2038 if (!inp->CheckFor(
"]")) {
2044 if (!inp->CheckFor(
">")) {
2054 Bool_t canhaschildren =
true;
2055 char endsymbol =
'/';
2058 if (*inp->fCurrent ==
'?') {
2059 if (!inp->ShiftCurrent())
2062 canhaschildren =
false;
2066 if (!inp->SkipSpaces())
2068 Int_t len = inp->LocateIdentifier();
2071 node = (SXmlNode_t *)AllocateNode(len, xmlparent);
2073 node->fType = nodetype;
2075 strncpy(nameptr, inp->fCurrent, len);
2080 if ((colon != 0) && (parent != 0)) {
2086 if (!inp->ShiftCurrent(len))
2090 if (!inp->SkipSpaces())
2093 char nextsymb = *inp->fCurrent;
2095 if (nextsymb == endsymbol) {
2096 if (!inp->ShiftCurrent())
2098 if (*inp->fCurrent ==
'>') {
2099 if (!inp->ShiftCurrent())
2105 inp->SkipSpaces(
kTRUE);
2110 }
else if (nextsymb ==
'>') {
2111 if (!canhaschildren) {
2116 if (!inp->ShiftCurrent())
2120 ReadNode(node, inp, resvalue);
2121 }
while (resvalue == 2);
2123 if (resvalue == 1) {
2129 Int_t attrlen = inp->LocateIdentifier();
2135 int valuelen = inp->LocateValue(attrlen,
true);
2141 SXmlAttr_t *attr = (SXmlAttr_t *)AllocateAttr(attrlen, valuelen - 3, (
XMLNodePointer_t)node);
2144 strncpy(attrname, inp->fCurrent, attrlen);
2145 attrname += attrlen;
2148 UnpackSpecialCharacters(attrname, inp->fCurrent + attrlen + 2, valuelen - 3);
2150 if (!inp->ShiftCurrent(attrlen + valuelen))
2155 if ((strlen(attrname) > 6) && (strstr(attrname,
"xmlns:") == attrname)) {
2160 if (node->fNs != 0) {
2178 case -14:
Error(
"ParseFile",
"Error include external XML file at line %d", linenumber);
break;
2179 case -13:
Error(
"ParseFile",
"Error processing DTD part of XML file at line %d", linenumber);
break;
2180 case -12:
Error(
"ParseFile",
"DOCTYPE missing after <! at line %d", linenumber);
break;
2182 Error(
"ParseFile",
"Node cannot be closed with > symbol at line %d, for instance <?xml ... ?> node", linenumber);
2185 Error(
"ParseFile",
"Error in xml comments definition at line %d, must be <!-- comments -->", linenumber);
2187 case -9:
Error(
"ParseFile",
"Multiple namespace definitions not allowed, line %d", linenumber);
break;
2188 case -8:
Error(
"ParseFile",
"Invalid namespace specification, line %d", linenumber);
break;
2189 case -7:
Error(
"ParseFile",
"Invalid attribute value, line %d", linenumber);
break;
2190 case -6:
Error(
"ParseFile",
"Invalid identifier for node attribute, line %d", linenumber);
break;
2191 case -5:
Error(
"ParseFile",
"Mismatch between open and close nodes, line %d", linenumber);
break;
2192 case -4:
Error(
"ParseFile",
"Unexpected close node, line %d", linenumber);
break;
2193 case -3:
Error(
"ParseFile",
"Valid identifier for close node is missing, line %d", linenumber);
break;
2194 case -2:
Error(
"ParseFile",
"No multiple content entries allowed, line %d", linenumber);
break;
2195 case -1:
Error(
"ParseFile",
"Unexpected end of xml file");
break;
2196 default:
Error(
"ParseFile",
"XML syntax error at line %d", linenumber);
break;
char * Makestr(const char *str)
creates char* variable with copy of provided string
XMLDocPointer_t ParseStream(TXMLInputStream *input)
parses content of the stream and tries to produce xml structures
void FreeAttr(XMLNodePointer_t xmlnode, const char *name)
remove attribute from xmlnode
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
return namespace attribute (if exists)
void SaveNode(XMLNodePointer_t xmlnode, TXMLOutputStream *out, Int_t layout, Int_t level)
stream data of xmlnode to output
Bool_t AddStyleSheet(XMLNodePointer_t parent, const char *href, const char *type="text/css", const char *title=0, int alternate=-1, const char *media=0, const char *charset=0)
Adds style sheet definition to the specified node Creates <?xml-stylesheet alternate="yes" title="com...
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
TXMLEngine()
if true, do not create comments nodes in document during parsing
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 ...
Bool_t AddComment(XMLNodePointer_t parent, const char *comment)
Adds comment line to the node.
XMLNsPointer_t FindNs(XMLNodePointer_t xmlnode, const char *nsname)
define if namespace of that name exists for xmlnode
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
return next attribute in the list
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
void UnlinkFreeNode(XMLNodePointer_t xmlnode)
combined operation. Unlink node and free used memory
XMLAttrPointer_t NewIntAttr(XMLNodePointer_t xmlnode, const char *name, Int_t value)
create node attribute with integer value
const char * GetNodeContent(XMLNodePointer_t xmlnode)
get contents (if any) of xmlnode
void DisplayError(Int_t error, Int_t linenumber)
Displays xml parsing error.
void FreeAllAttr(XMLNodePointer_t xmlnode)
Free all attributes of the node.
The TNamed class is the base class for all named ROOT classes.
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
void Init(TClassEdit::TInterpreterLookupHelper *helper)
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=0)
create namespace attribute for xmlnode.
TString & Append(const char *cs)
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
Bool_t IsEmptyNode(XMLNodePointer_t xmlnode)
return kTRUE is this is node with special data like comments to data processing instructions ...
void Error(const char *location, const char *msgfmt,...)
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
XMLAttrPointer_t AllocateAttr(int namelen, int valuelen, XMLNodePointer_t xmlnode)
Allocate new attribute with specified name length and value length.
Int_t GetLast() const
Return index of last object in array.
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 AddChild(XMLNodePointer_t parent, XMLNodePointer_t child)
add child element to xmlnode
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 ...
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...
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
char * Makenstr(const char *start, int len)
creates char* variable with copy of len symbols from provided string
Bool_t IsCommentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
return value of attribute
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
return first attribute in the list, namespace (if exists) will be skipped
Bool_t AddDocStyleSheet(XMLDocPointer_t xmldoc, const char *href, const char *type="text/css", const char *title=0, int alternate=-1, const char *media=0, const char *charset=0)
Add style sheet definition on the top of document.
void SkipEmpty(XMLNodePointer_t &xmlnode)
Skip all current empty nodes and locate on first "true" node.
Bool_t IsXmlNode(XMLNodePointer_t xmlnode)
return kTRUE is this is normal xmlnode
Bool_t HasAttr(XMLNodePointer_t xmlnode, const char *name)
checks if node has attribute of specified name
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...
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
void AddChildFirst(XMLNodePointer_t parent, XMLNodePointer_t child)
add node as first child
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 CleanNode(XMLNodePointer_t xmlnode)
remove all children node from xmlnode
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
returns value of attribute for xmlnode
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...
Bool_t AddDocComment(XMLDocPointer_t xmldoc, const char *comment)
add comment line to the top of the document
void TruncateNsExtension(XMLNodePointer_t xmlnode)
removes namespace extension of nodename
void FreeNode(XMLNodePointer_t xmlnode)
release all memory, allocated from this node and destroys node itself
XMLNodePointer_t ReadNode(XMLNodePointer_t xmlparent, TXMLInputStream *inp, Int_t &resvalue)
Tries to construct xml node from input stream.
Bool_t ValidateVersion(XMLDocPointer_t doc, const char *version=0)
check that first node is xml processing instruction with correct xml version number ...
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
XMLNodePointer_t GetParent(XMLNodePointer_t xmlnode)
returns parent of xmlnode
void UnpackSpecialCharacters(char *target, const char *source, int srclen)
unpack special symbols, used in xml syntax to code characters these symbols: '<' - <, '>' - >, '&' - &, '"...
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=0)
create new child element for parent node
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
void UnlinkNode(XMLNodePointer_t node)
unlink (detach) xmlnode from parent
Int_t GetIntAttr(XMLNodePointer_t node, const char *name)
returns value of attribute as integer
Bool_t IsContentNode(XMLNodePointer_t xmlnode)
return kTRUE is this is special node with content
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 ...
XMLNodePointer_t ReadSingleNode(const char *src)
read single xmlnode from provided string
virtual ~TXMLEngine()
destructor for TXMLEngine object
void OutputValue(char *value, TXMLOutputStream *out)
output value to output stream if symbols '<' '&' '>' '"' ''' appears in the string, they will be encoded to appropriate xml symbols: <, &, >, ", &apos
const char * GetAttrName(XMLAttrPointer_t xmlattr)
return name of the attribute
static constexpr double ns
XMLNodePointer_t AllocateNode(int namelen, XMLNodePointer_t parent)
Allocates new xml node with specified name length.
const char * GetNSReference(XMLNsPointer_t ns)
return reference id of namespace
void AssignDtd(XMLDocPointer_t xmldoc, const char *dtdname, const char *rootname)
assigns dtd filename to document