XML/DTD question, please help me out.

M

Martijn

Hi,

I'm new in the XML world. I need to program a C++ application that
writes information of all directories and files on the harddisk to a
XML file. Now that's not really the problem.

I expect part of the XML file could look like this:

<FILELIST>
<DIRECTORY name="windows" date="09/23/2003">
<FILE>
<FILENAME>win.ini</FILENAME>
<FILESIZE>1128</FILESIZE>
<FILEDATE>09/23/2003</FILEDATE>
</FILE>
<DIRECTORY name="system" date="09/23/2003">
<FILE>
<FILENAME>keyboard.drv</FILENAME>
<FILESIZE>2000</FILESIZE>
<FILEDATE>09/23/2003</FILEDATE>
</FILE>
</DIRECTORY>
</DIRECTORY>
</FILELIST>

Correct me when I'm wrong.

And for the DTD file:

<!DOCTYPE FILELIST [

<!ELEMENT FILELIST (DIRECTORY*)>
<!ELEMENT DIRECTORY (DIRECTORYNAME, DIRECTORYDATE, FILE*)>
<!ELEMENT DIRECTORYNAME (#PCDATA)>
<!ELEMENT DIRECTORYDATE (#PCDATA)>
<!ELEMENT FILE (FILENAME, FILESIZE, FILEDATE)>
<!ELEMENT FILENAME (#PCDATA)>
<!ELEMENT FILESIZE (#PCDATA)>
<!ELEMENT FILEDATE (#PCDATA)>

<!ATTLIST DIRECTORY NAME CDATA #REQUIRED>
<!ATTLIST DIRECTORY DATE CDATA #REQUIRED>

]>

Now my question:

Directories can excist in directories wich can excist in directories,
etc.
How to solve this in the DTD file.

-Martijn
 
M

Martin Boehm

Martijn said:
Hi,

I'm new in the XML world. I need to program a C++ application that
writes information of all directories and files on the harddisk to a
XML file. Now that's not really the problem.

[...]

And for the DTD file:

<!DOCTYPE FILELIST [

<!ELEMENT FILELIST (DIRECTORY*)>
<!ELEMENT DIRECTORY (DIRECTORYNAME, DIRECTORYDATE, FILE*)>

According to your samle XML, this is wrong. You should, but do not have
any DIRECTORYNAME or DIRECTORYDATE elements, you use attributes, as you
correctly denoted later. But you would have noticed, I guess. ;-)
Now my question:

Directories can excist in directories wich can excist in directories,
etc.
How to solve this in the DTD file.

<!ELEMENT DIRECTORY (DIRECTORY*, FILE*)>

What did you think? ;-) Self-referencing is allowed in DTDs.

Martin
 
M

Martijn

Martin Boehm said:
Martijn said:
Hi,

I'm new in the XML world. I need to program a C++ application that
writes information of all directories and files on the harddisk to a
XML file. Now that's not really the problem.

[...]

And for the DTD file:

<!DOCTYPE FILELIST [

<!ELEMENT FILELIST (DIRECTORY*)>
<!ELEMENT DIRECTORY (DIRECTORYNAME, DIRECTORYDATE, FILE*)>

According to your samle XML, this is wrong. You should, but do not have
any DIRECTORYNAME or DIRECTORYDATE elements, you use attributes, as you
correctly denoted later. But you would have noticed, I guess. ;-)
Stupid of me.
<!ELEMENT DIRECTORY (DIRECTORY*, FILE*)>

What did you think? ;-) Self-referencing is allowed in DTDs.

That's what I didn't know.

Thanks
Martijn
 
M

Micah Cowan

Martin Boehm said:
<!ELEMENT DIRECTORY (DIRECTORY*, FILE*)>

What did you think? ;-) Self-referencing is allowed in DTDs.

<!ELEMENT DIRECTORY (DIRECTORY | FILE)*>

Would allow intermixing between DIRECTORYs and FILEs.

-Micah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top