I'm looking to search within blocks of XML that are rather old (documents dated 1999) and I'm having a little bit of difficulty getting TinyXML2 to operate as intended. I can grab certain snippets but I have issues when there's an element within another one. Take this sample:
<SUBJECT><TITLE>Mathematics</TITLE></SUBJECT>
<AREA><TITLE>Arithmetic</TITLE></AREA>
<SECTION><TITLE>Whole Numbers</TITLE></SECTION>
<TOPIC GRADELEVEL="4"><TITLE>Introduction to Numbers</TITLE></TOPIC>
<DESCRIPTION><TITLE>Description</TITLE></DESCRIPTION>
<FIELDSPACE>
<PARA>To represent each conceivable number by means of a separate
little picture or number symbol is impossible. Therefore the civilizations of
the past all developed a certain pattern whereby they could write down numbers,
by making use of a small number of symbols. </PARA>
</FIELDSPACE>
<FIELDSPACE>
<PARA>Today, we use the Hindu-Arabic system, which first of all is
decimal, because we make use of only 10 different symbols, namely,</PARA>
<LITERALLAYOUT> 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.</LITERALLAYOUT>
</FIELDSPACE>
<FIELDSPACE>
<PARA>Secondly, a place value applies. This means that if only 1
digit is written down then it is that number, such as a 3, a 6, or an 8.</PARA>
</FIELDSPACE>
<FIELDSPACE>
<PARA>Thirdly, only the addition principle is built into our number
symbols.</PARA>
<PARA>In other words,</PARA>
<LITERALLAYOUT> 135 means 100 + 300 + 5</LITERALLAYOUT>
<LITERALLAYOUT> 6.3 means 6 + three tenths = 6 + <EQUATION>
<INLINEGRAPHIC FILEREF="Mathematics/Arithmetic/WholeNumbers/IntroductionNumbers/eq.png" />
</EQUATION></LITERALLAYOUT>
<LITERALLAYOUT> and two and a quarter = <EQUATION>
<INLINEGRAPHIC FILEREF="Mathematics/Arithmetic/WholeNumbers/IntroductionNumbers/eq2.png" />
</EQUATION></LITERALLAYOUT>
<PARA>means</PARA>
<LITERALLAYOUT> two plus a quarter = <EQUATION>
<INLINEGRAPHIC FILEREF="Mathematics/Arithmetic/WholeNumbers/IntroductionNumbers/eq3.png" />
</EQUATION></LITERALLAYOUT>
</FIELDSPACE>
Here is what I've written:
XMLDocument doc;
Resource::resource_t *f = Resource::Open("IntroductionNumbers.xml"); // File load
if (!f)
return;
doc.Parse((const char*)f->buffer, f->size);
Resource::Close(f);
XMLElement *pElem;
pElem = doc.FirstChildElement();
if (!pElem)
return;
for (pElem = pElem->FirstChildElement(); pElem; pElem = pElem->NextSiblingElement())
{
if (!strcmp(pElem->Value(), "SUBJECT"))
{
// Print what's in pElem->FirstChildElement("TITLE")->GetText()
// This works fine.
}
else if (!strcmp(pElem->Value(), "AREA"))
{
// Print what's in pElem->FirstChildElement("TITLE")->GetText()
// This works fine.
}
...
...
...
else if (!strcmp(pElem->Value(), "TOPIC"))
{
char *temp;
temp = msprintf("%s - Section %s", pElem->FirstChildElement("TITLE")->GetText(), pElem->FirstAttribute()->Value());
// Print what's in temp
// This still works!
}
else if (!strcmp(pElem->Value(), "FIELDSPACE"))
{
// I can print PARA or FIELDSPACE, but I can't seem to read LITERALLAYOUT, EQUATION, or INLINEGRAPHIC.
}
}
I need code that is generic instead of code specific to this solution - there are hundreds of XML files and I need to write something that will parse all of them. How would I grab information within LITERALLAYOUT/EQUATION/INLINEGRAPHIC?
Thanks in advance!