0

I'm just learning XML, and what I'm specifically wanting to use it for is including external files. e.g. a single contact details file, which you then include in all pages that need to have contact details in them.

I've seen several examples talking about doing something similar with book chapters, and they show what the main file should look like, but none of the examples show what the file to be included should look like, and I can't get it to work! Could someone please let me know what I need to change here? At the moment I just get a blank page when I open the main file (the "chapter" file displays fine on it's own, just not when I try to include it in the other). I'm on Windows 10 and just using IE to display it (was the only browser I had that actually "just works"!). They are in the same directory.

Here are what my 2 files currently look like (the first was just copied directly from somewhere, and I'm trying to work out what should be in the second file for the first to work, unless there's something wrong with the first one to begin with?)...

<?xml version="1.0" standalone="no"?>
<!DOCTYPE book [
  <!ELEMENT book (chapter)*>
  <!ELEMENT chapter ANY>
  <!ENTITY BookChapter1 SYSTEM "TestChapter1.xhtml">
]><book>&BookChapter1;</book>
<?xml version="1.0" encoding="UTF-8"?>
This is Chapter 1
donaldp
  • 220
  • 1
  • 3
  • 15
  • Does this answer your question? [How can I "include" one XML file into another XML file?](https://stackoverflow.com/questions/4353520/how-can-i-include-one-xml-file-into-another-xml-file) – Filburt Jul 17 '21 at 10:46
  • Thanks @Filburt. Didn't see that one when I was first looking, but no, doesn't answer as far as I can see. That one is using schemas, which I know nothing about yet, and there is debate anyway as to how widely supported XInclude is. A couple of people have said to use entities instead, which is what I'm using, but I can't find why mine isn't working (since, yet again, no-one in the answers said what the included file should look like). – donaldp Jul 17 '21 at 11:26
  • I am not sure using XML in the browser, particularly loaded from the local file system, is a good environment to use stuff like external entities. If I am not mistaken, however, your second file with the "external parsed entity" `BookChapter1` is not allowed any DOCTYPE declaration, the grammar in https://www.w3.org/TR/xml/#TextEntities defines `extParsedEnt ::= TextDecl? content`, and a DOCTYPE is neither part of the optional TextDeclaration nor of the content. Furthermore, for the first file use `DOCTYPE book` if the root element is `book`, no idea where `experiment_a` comes from. – Martin Honnen Jul 17 '21 at 17:25
  • Thanks for that info @MartinHonnen. I did think there would be some rules around the included document (which adds to the frustration of no examples showing an included text file) so what you said makes sense. ATM this is just me learning how to use it on my own computer. I don't know where experiment_a came from either - I just copied the example given (which unfortunately gave no example of the included file) - I'm thinking (or they were) that you can't use book as both the doctype and an element? Did what I think you mean, but not working. I'l update original with current state – donaldp Jul 18 '21 at 07:09

0 Answers0