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;
801 cnode->fParent = pnode;
802 if (pnode->fLastChild == 0) {
803 pnode->fChild = cnode;
804 pnode->fLastChild = cnode;
808 pnode->fLastChild->fNext = cnode;
809 pnode->fLastChild = cnode;
818 if ((parent == 0) || (child == 0))
820 SXmlNode_t *pnode = (SXmlNode_t *)parent;
821 SXmlNode_t *cnode = (SXmlNode_t *)child;
826 cnode->fParent = pnode;
828 cnode->fNext = pnode->fChild;
829 pnode->fChild = cnode;
831 if (pnode->fLastChild == 0)
832 pnode->fLastChild = cnode;
840 if (afternode == 0) {
841 AddChild(parent, child);
845 SXmlNode_t *pnode = (SXmlNode_t *)parent;
846 SXmlNode_t *cnode = (SXmlNode_t *)child;
847 SXmlNode_t *anode = (SXmlNode_t *)afternode;
849 if (anode->fParent != pnode) {
850 Error(
"InsertChildAfter",
"Specified afternode is not in childs list of parent node");
851 AddChild(parent, child);
858 cnode->fParent = pnode;
860 cnode->fNext = anode->fNext;
861 anode->fNext = cnode;
863 if (pnode->fLastChild == anode)
864 pnode->fLastChild = cnode;
872 if ((xmlnode == 0) || (comment == 0))
875 int commentlen = strlen(comment);
877 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(commentlen, xmlnode);
893 UnlinkNode(rootnode);
895 Bool_t res = AddComment(((SXmlDoc_t *)xmldoc)->fRootNode, comment);
909 if ((xmlnode == 0) || (line == 0))
912 int linelen = strlen(line);
913 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(linelen, xmlnode);
927 UnlinkNode(rootnode);
929 Bool_t res = AddRawLine(((SXmlDoc_t *)xmldoc)->fRootNode, line);
946 int alternate,
const char *media,
const char *charset)
948 if ((xmlnode == 0) || (href == 0) || (type == 0))
951 const char *nodename =
"xml-stylesheet";
952 int nodenamelen = strlen(nodename);
954 SXmlNode_t *node = (SXmlNode_t *)AllocateNode(nodenamelen, xmlnode);
959 NewAttr(node, 0,
"alternate", (alternate > 0) ?
"yes" :
"no");
962 NewAttr(node, 0,
"title", title);
964 NewAttr(node, 0,
"href", href);
965 NewAttr(node, 0,
"type", type);
968 NewAttr(node, 0,
"media", media);
970 NewAttr(node, 0,
"charset", charset);
979 int alternate,
const char *media,
const char *charset)
985 UnlinkNode(rootnode);
987 Bool_t res = AddStyleSheet(((SXmlDoc_t *)xmldoc)->fRootNode, href, type, title, alternate, media, charset);
1002 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1003 SXmlNode_t *parent = node->fParent;
1008 if (parent->fChild == node) {
1009 parent->fChild = node->fNext;
1010 if (parent->fLastChild == node)
1011 parent->fLastChild = node->fNext;
1013 SXmlNode_t *ch = parent->fChild;
1014 while (ch->fNext != node)
1016 ch->fNext = node->fNext;
1017 if (parent->fLastChild == node)
1018 parent->fLastChild = ch;
1033 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1035 SXmlNode_t *child = node->fChild;
1036 while (child != 0) {
1037 SXmlNode_t *next = child->fNext;
1042 SXmlAttr_t *attr = node->fAttr;
1044 SXmlAttr_t *next = attr->fNext;
1060 UnlinkNode(xmlnode);
1079 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1080 if (node->fChild == 0)
1097 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1098 if ((node->fChild != 0) && (node->fChild->fType ==
kXML_CONTENT))
1104 len = strlen(content);
1106 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(len, 0);
1109 strncpy(nameptr, content, len);
1122 if ((xmlnode == 0) || (content == 0))
1125 len = strlen(content);
1127 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(len, xmlnode);
1130 strncpy(nameptr, content, len);
1142 if (realnode && (res != 0) && (((SXmlNode_t *)res)->fType !=
kXML_NODE))
1143 ShiftToNext(res,
kTRUE);
1152 return xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fParent;
1162 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1163 if ((xmlnode == 0) || !realnode)
1165 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1177 xmlnode = xmlnode == 0 ? 0 : (
XMLNodePointer_t)((SXmlNode_t *)xmlnode)->fNext;
1178 if ((xmlnode == 0) || !realnode)
1180 }
while (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1188 return xmlnode == 0 ?
kFALSE : (((SXmlNode_t *)xmlnode)->fType ==
kXML_NODE);
1196 return xmlnode == 0 ?
kTRUE : (((SXmlNode_t *)xmlnode)->fType !=
kXML_NODE);
1220 if (IsEmptyNode(xmlnode))
1221 ShiftToNext(xmlnode);
1231 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1233 SXmlNode_t *child = node->fChild;
1234 while (child != 0) {
1235 SXmlNode_t *next = child->fNext;
1241 node->fLastChild = 0;
1249 SXmlDoc_t *doc =
new SXmlDoc_t;
1250 doc->fRootNode = (SXmlNode_t *)NewChild(0, 0,
"??DummyTopNode??", 0);
1255 NewAttr(vernode, 0,
"version", version);
1270 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1271 delete[] doc->fDtdName;
1272 doc->fDtdName = Makestr(dtdname);
1273 delete[] doc->fDtdRoot;
1274 doc->fDtdRoot = Makestr(rootname);
1284 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1286 delete[] doc->fDtdName;
1287 delete[] doc->fDtdRoot;
1303 SXmlDoc_t *doc = (SXmlDoc_t *)xmldoc;
1305 TXMLOutputStream out(filename, 100000);
1310 SaveNode(child, &out, layout, 0);
1311 ShiftToNext(child,
kFALSE);
1312 }
while (child != 0);
1323 FreeNode(DocGetRootElement(xmldoc));
1340 return GetChild(xmlnode,
kTRUE);
1350 if ((filename == 0) || (strlen(filename) == 0))
1352 if (maxbuf < 100000)
1354 TXMLInputStream inp(
true, filename, maxbuf);
1355 return ParseStream(&inp);
1363 if ((xmlstring == 0) || (strlen(xmlstring) == 0))
1365 TXMLInputStream inp(
false, xmlstring, 2 * strlen(xmlstring));
1366 return ParseStream(&inp);
1384 ReadNode(((SXmlDoc_t *)xmldoc)->fRootNode, inp, resvalue);
1391 if (!inp->EndOfStream())
1394 if (inp->EndOfStream()) {
1401 DisplayError(resvalue, inp->CurrentLine());
1423 if (strcmp(GetNodeName(vernode),
"xml") != 0)
1426 const char *value = GetAttr(vernode,
"version");
1432 return strcmp(version, value) == 0;
1444 if ((res == 0) || (xmlnode == 0))
1447 TXMLOutputStream out(res, 10000);
1449 SaveNode(xmlnode, &out, layout, 0);
1460 TXMLInputStream inp(
false, src, 10000);
1466 if (resvalue <= 0) {
1467 DisplayError(resvalue, inp.CurrentLine());
1482 int len = strlen(str);
1485 char *res =
new char[len + 1];
1486 strncpy(res, str, len + 1);
1495 if ((str == 0) || (len == 0))
1497 char *res =
new char[len + 1];
1498 strncpy(res, str, len);
1510 SXmlNode_t *node = (SXmlNode_t *)
malloc(
sizeof(SXmlNode_t) + namelen + 1);
1517 node->fLastChild = 0;
1533 SXmlAttr_t *attr = (SXmlAttr_t *)
malloc(
sizeof(SXmlAttr_t) + namelen + 1 + valuelen + 1);
1535 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1539 if (node->fAttr == 0)
1542 SXmlAttr_t *
d = node->fAttr;
1543 while (d->fNext != 0)
1556 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1558 if (node->fNs != 0) {
1560 if (strcmp(nsname, name) == 0)
1563 node = node->fParent;
1573 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1583 *(copyname++) = *(++colon);
1592 while (srclen > 0) {
1593 if (*source ==
'&') {
1594 if ((srclen > 3) && (*(source + 1) ==
'l') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1598 }
else if ((srclen > 3) && (*(source + 1) ==
'g') && (*(source + 2) ==
't') && (*(source + 3) ==
';')) {
1602 }
else if ((srclen > 4) && (*(source + 1) ==
'a') && (*(source + 2) ==
'm') && (*(source + 3) ==
'p') &&
1603 (*(source + 4) ==
';')) {
1607 }
else if ((srclen > 5) && (*(source + 1) ==
'q') && (*(source + 2) ==
'u') && (*(source + 3) ==
'o') &&
1608 (*(source + 4) ==
't') && (*(source + 5) ==
';')) {
1612 }
else if ((srclen > 5) && (*(source + 1) ==
'a') && (*(source + 2) ==
'p') && (*(source + 3) ==
'o') &&
1613 (*(source + 4) ==
's') && (*(source + 5) ==
';')) {
1618 *target++ = *source++;
1622 *target++ = *source++;
1641 while ((find = strpbrk(last,
"<&>\"")) != 0) {
1649 else if (symb ==
'>')
1651 else if (symb ==
'&')
1652 out->Write(
"&");
1653 else if (symb ==
'\'')
1654 out->Write(
"'");
1656 out->Write(
""");
1669 SXmlNode_t *node = (SXmlNode_t *)xmlnode;
1671 Bool_t issingleline = (node->fChild == 0);
1674 out->Put(
' ', level);
1700 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1706 SXmlAttr_t *attr = node->fAttr;
1710 out->Write(attrname);
1712 attrname += strlen(attrname) + 1;
1713 OutputValue(attrname, out);
1731 SXmlNode_t *child = node->fChild;
1733 if ((child != 0) && (child->fType ==
kXML_CONTENT) && (child->fNext == 0)) {
1739 while (child != 0) {
1741 child = child->fNext;
1745 out->Put(
' ', level);
1750 if ((node->fNs != 0) && (node->fNs != node->fAttr)) {
1773 if (!inp->SkipSpaces()) {
1777 SXmlNode_t *parent = (SXmlNode_t *)xmlparent;
1779 SXmlNode_t *node = 0;
1782 while (inp->CheckFor(
"<!--")) {
1783 Int_t commentlen = inp->SearchFor(
"-->");
1784 if (commentlen <= 0) {
1789 if (!fSkipComments) {
1790 node = (SXmlNode_t *)AllocateNode(commentlen, xmlparent);
1793 strncpy(nameptr, inp->fCurrent, commentlen);
1794 nameptr += commentlen;
1798 if (!inp->ShiftCurrent(commentlen + 3)) {
1802 if (!inp->SkipSpaces() && !inp->EndOfStream()) {
1811 if (*inp->fCurrent !=
'<') {
1818 int contlen = inp->LocateContent();
1822 SXmlNode_t *contnode = (SXmlNode_t *)AllocateNode(contlen, xmlparent);
1825 UnpackSpecialCharacters(contptr, inp->fCurrent, contlen);
1826 if (!inp->ShiftCurrent(contlen))
1829 if (inp->NumEntities() <= 0) {
1836 const char *beg(0), *lastentity(0), *curr(contptr);
1838 while (*curr != 0) {
1839 if ((beg == 0) && (*curr ==
'&'))
1841 if ((beg == 0) || (*curr !=
';')) {
1846 TXMLEntity *entity = inp->FindEntity(beg + 1, curr - beg - 1);
1850 if (lastentity == 0) {
1851 lastentity = contptr;
1852 UnlinkNode(contnode);
1855 if (lastentity != beg)
1856 AddNodeContent(xmlparent, lastentity, beg - lastentity);
1858 if (entity->IsSystem()) {
1860 if (entitydoc == 0) {
1867 while (topnode != 0) {
1869 ShiftToNext(topnode,
false);
1870 UnlinkNode(currnode);
1871 AddChild(xmlparent, currnode);
1874 AddNodeContent(xmlparent, entity->GetTitle());
1884 if (lastentity != 0) {
1886 if (strlen(lastentity) > 0)
1887 AddNodeContent(xmlparent, lastentity);
1897 if (!inp->ShiftCurrent())
1901 if (*inp->fCurrent ==
'/') {
1903 if (!inp->ShiftCurrent())
1905 if (!inp->SkipSpaces())
1907 Int_t len = inp->LocateIdentifier();
1923 if (!inp->ShiftCurrent(len))
1926 if (!inp->SkipSpaces())
1928 if (*inp->fCurrent !=
'>')
1930 if (!inp->ShiftCurrent())
1933 if (parent->fNs != 0)
1936 inp->SkipSpaces(
kTRUE);
1941 if (*inp->fCurrent ==
'!') {
1943 if (!inp->ShiftCurrent())
1945 if (!inp->CheckFor(
"DOCTYPE")) {
1949 if (!inp->SkipSpaces()) {
1955 Int_t len = inp->LocateIdentifier();
1960 if (!inp->ShiftCurrent(len)) {
1964 if (!inp->SkipSpaces()) {
1970 if (inp->CheckFor(
"[")) {
1971 if (!inp->SkipSpaces())
1974 if (inp->CheckFor(
"<!ENTITY")) {
1976 if (!inp->SkipSpaces()) {
1980 Int_t namelen = inp->LocateIdentifier();
1985 TString entity_name(inp->fCurrent, namelen);
1986 if (!inp->ShiftCurrent(namelen)) {
1990 if (!inp->SkipSpaces()) {
1995 if (inp->CheckFor(
"SYSTEM")) {
1996 if (!inp->SkipSpaces()) {
2003 Int_t valuelen = inp->LocateValue(0,
false);
2009 TString entity_value(inp->fCurrent + 1, valuelen - 2);
2011 if (!inp->ShiftCurrent(valuelen)) {
2016 if (*inp->fCurrent !=
'>') {
2020 if (!inp->ShiftCurrent()) {
2026 inp->AddEntity(
new TXMLEntity(entity_name, entity_value, is_system));
2030 if (inp->CheckFor(
"<!ELEMENT")) {
2032 if (!inp->SkipSpaces()) {
2036 Int_t namelen = inp->LocateIdentifier();
2042 if (!inp->ShiftCurrent(namelen)) {
2046 if (!inp->SkipSpaces()) {
2051 if (!inp->CheckFor(
"(")) {
2055 if (inp->SearchFor(
")") <= 0) {
2061 if (*inp->fCurrent !=
'>') {
2065 if (!inp->ShiftCurrent()) {
2077 if (!inp->CheckFor(
"]")) {
2083 if (!inp->CheckFor(
">")) {
2093 Bool_t canhaschildren =
true;
2094 char endsymbol =
'/';
2097 if (*inp->fCurrent ==
'?') {
2098 if (!inp->ShiftCurrent())
2101 canhaschildren =
false;
2105 if (!inp->SkipSpaces())
2107 Int_t len = inp->LocateIdentifier();
2110 node = (SXmlNode_t *)AllocateNode(len, xmlparent);
2112 node->fType = nodetype;
2114 strncpy(nameptr, inp->fCurrent, len);
2119 if ((colon != 0) && (parent != 0)) {
2125 if (!inp->ShiftCurrent(len))
2129 if (!inp->SkipSpaces())
2132 char nextsymb = *inp->fCurrent;
2134 if (nextsymb == endsymbol) {
2135 if (!inp->ShiftCurrent())
2137 if (*inp->fCurrent ==
'>') {
2138 if (!inp->ShiftCurrent())
2144 inp->SkipSpaces(
kTRUE);
2149 }
else if (nextsymb ==
'>') {
2150 if (!canhaschildren) {
2155 if (!inp->ShiftCurrent())
2159 ReadNode(node, inp, resvalue);
2160 }
while (resvalue == 2);
2162 if (resvalue == 1) {
2168 Int_t attrlen = inp->LocateIdentifier();
2174 int valuelen = inp->LocateValue(attrlen,
true);
2180 SXmlAttr_t *attr = (SXmlAttr_t *)AllocateAttr(attrlen, valuelen - 3, (
XMLNodePointer_t)node);
2183 strncpy(attrname, inp->fCurrent, attrlen);
2184 attrname += attrlen;
2187 UnpackSpecialCharacters(attrname, inp->fCurrent + attrlen + 2, valuelen - 3);
2189 if (!inp->ShiftCurrent(attrlen + valuelen))
2194 if ((strlen(attrname) > 6) && (strstr(attrname,
"xmlns:") == attrname)) {
2199 if (node->fNs != 0) {
2217 case -14:
Error(
"ParseFile",
"Error include external XML file at line %d", linenumber);
break;
2218 case -13:
Error(
"ParseFile",
"Error processing DTD part of XML file at line %d", linenumber);
break;
2219 case -12:
Error(
"ParseFile",
"DOCTYPE missing after <! at line %d", linenumber);
break;
2221 Error(
"ParseFile",
"Node cannot be closed with > symbol at line %d, for instance <?xml ... ?> node", linenumber);
2224 Error(
"ParseFile",
"Error in xml comments definition at line %d, must be <!-- comments -->", linenumber);
2226 case -9:
Error(
"ParseFile",
"Multiple namespace definitions not allowed, line %d", linenumber);
break;
2227 case -8:
Error(
"ParseFile",
"Invalid namespace specification, line %d", linenumber);
break;
2228 case -7:
Error(
"ParseFile",
"Invalid attribute value, line %d", linenumber);
break;
2229 case -6:
Error(
"ParseFile",
"Invalid identifier for node attribute, line %d", linenumber);
break;
2230 case -5:
Error(
"ParseFile",
"Mismatch between open and close nodes, line %d", linenumber);
break;
2231 case -4:
Error(
"ParseFile",
"Unexpected close node, line %d", linenumber);
break;
2232 case -3:
Error(
"ParseFile",
"Valid identifier for close node is missing, line %d", linenumber);
break;
2233 case -2:
Error(
"ParseFile",
"No multiple content entries allowed, line %d", linenumber);
break;
2234 case -1:
Error(
"ParseFile",
"Unexpected end of xml file");
break;
2235 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 AddChildAfter(XMLNodePointer_t parent, XMLNodePointer_t child, XMLNodePointer_t afternode)
Insert new child node after already existing node.
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