Back-of-book index in XML

  • Thread starter Thread starter Gustaf Liljegren
  • Start date Start date
G

Gustaf Liljegren

Hi,

I've been struggling with this for days now. Hope to get some help here,
but some knowlegde in XML is required. I'm trying to create a back-of-
book index in XML, following this DTD:

<!ELEMENT index (entry | group)*>
<!ELEMENT entry (text, pages)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ELEMENT group (text, pages?, entry*)>

Here's a small example:

<index>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
<group>
<text>...</text>
<pages>...</pages>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
</group>
</index>

I have extracted all the data, and it's currently in an ArrayList of
IndexEntry objects (not sorted), that consists of the properties Text,
Group and Pages. Text is typically what is conntected to the page number
(but may also be conntected to a group). Group is the name of a group,
and Pages is a string like "12, 14-17". A few examples, and their XML
equivalences:

---

Text: apples
Context:
Pages: 12, 14-17

=

<entry>
<text>apples</text>
<pages>12, 14-17</pages>
</entry>

---

Text: apples
Context: fruits
Pages: 12, 14-17

+

Text: fruits
Context:
Pages: 11

=

<group>
<text>fruits</text>
<pages>11</pages>
<entry>
<text>apples</text>
<pages>12, 14-17</pages>
</entry>
</group>

---

The last example shows that if there are entries where the Group property
is matching the Text property of other entries, they shall be grouped
together.

I have been using SortedList in my attempts, with keys consisting of
Group (if any) + Text, so I get a sorted list like this:

berries
fruits/apples
fruits/bananas
fruits/pinapple
juice
milk

Maybe there's a way to use this sorting, but I don't know how.

I'm not asking for a complete solution, just some advice on how to
approach it. Some pseudo-code would be fine.

Gustaf
 
try the XML newsgroup, you'll probably get more help there.

Dan.

Hi,

I've been struggling with this for days now. Hope to get some help here,
but some knowlegde in XML is required. I'm trying to create a back-of-
book index in XML, following this DTD:

<!ELEMENT index (entry | group)*>
<!ELEMENT entry (text, pages)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ELEMENT group (text, pages?, entry*)>

Here's a small example:

<index>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
<group>
<text>...</text>
<pages>...</pages>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
<entry>
<text>...</text>
<pages>...</pages>
</entry>
</group>
</index>

I have extracted all the data, and it's currently in an ArrayList of
IndexEntry objects (not sorted), that consists of the properties Text,
Group and Pages. Text is typically what is conntected to the page number
(but may also be conntected to a group). Group is the name of a group,
and Pages is a string like "12, 14-17". A few examples, and their XML
equivalences:

---

Text: apples
Context:
Pages: 12, 14-17

=

<entry>
<text>apples</text>
<pages>12, 14-17</pages>
</entry>

---

Text: apples
Context: fruits
Pages: 12, 14-17

+

Text: fruits
Context:
Pages: 11

=

<group>
<text>fruits</text>
<pages>11</pages>
<entry>
<text>apples</text>
<pages>12, 14-17</pages>
</entry>
</group>

---

The last example shows that if there are entries where the Group property
is matching the Text property of other entries, they shall be grouped
together.

I have been using SortedList in my attempts, with keys consisting of
Group (if any) + Text, so I get a sorted list like this:

berries
fruits/apples
fruits/bananas
fruits/pinapple
juice
milk

Maybe there's a way to use this sorting, but I don't know how.

I'm not asking for a complete solution, just some advice on how to
approach it. Some pseudo-code would be fine.

Gustaf
 
Back
Top