Hello,
I have been using TXMLFile to read a test.xml file lately.
It turns out that the TXMLFile is empty. Am I missing something ?
TXMLFile *ff = new TXMLFile("./test.xml");
std::cout << ff->GetSize() << std::endl;
Here are some test files.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<main>
<child1>Content of child1 node</child1>
<child2 attr1="value1" attr2="value2"/>
<child3>
<subchild1>subchild1 content</subchild1>
<subchild2>subchild2 content</subchild2>
<subchild3>subchild3 content</subchild3>
</child3>
<child4 xmlns:child4="http://website/webpage">
<child4:subchild1>subchild1 content</child4:subchild1>
<child4:subchild2>subchild2 content</child4:subchild2>
<child4:subchild3>subchild3 content</child4:subchild3>
</child4>
</main>
linev
2
Hi,
TXMLFile
class has its own layout and designed to store objects - like histograms or graphs.
If you want to parse arbitrary XML file, you have to use generic XML parser.
See tutorials with simple XML parser:
xmlnewfile.C
xmlreadfile.C
Or more complex one with libxml2:
DOMParsePerson.C
All XML-related tutorials are:
https://root.cern/doc/master/group__tutorial__xml.html
Regards,
Sergey
Hi, I see.
Simple XML parser tutorial didn’t seems to work neither. Is that expected ?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I would be happy to follow TXMLFile layout.
Is there any TXMLFile tutorial too ?
linev
4
It can be used as normal ROOT file:
auto obj = new TNamed("name", "title");
auto f = TFile::Open("file.xml", "recreate");
obj->Write("t1");
delete f;
And then:
auto f1 = TFile::Open("file.xml");
auto obj1 = f1->Get("t1");
obj1->Print();
I would not recommend trying to reproduce layout of this XML file - it has several special components like streamer infos or directory organization.
Just use functionality of TFile
class. See documentation:
https://root.cern/doc/master/classTFile.html
Thanks for the explanation! Sounds clear now
Actually none of the xml files with a DTD are not loading with TXMLEngine.
I actually need to have this line in these files
Do you have a suggestion how to fix it ?
linev
6
TXMLEngine
is simple but fast parser, which does not support DTD.
You should try to use TDOMParser
class.
1 Like
system
Closed
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.