I guess this question has been asked to death - so here I bring it up again.....

I have this XML page and right now there is an <about> tag that contains information the page name and copyright information.

However the copyright information contains something like 1998-2006 and so instead of going through each XML page to update the year, I would like to extract this whole <about> tag into another file, which each XML can then include. However the <about> tag also contains the module id, e.g. mEmployeeDetail.

So how should I do this then? I am new to XML and worse yet I'm maintaining someone's XML code.

My <about> is not at the top of the page, so if I put that right before my <about> tag I got an error:

Cannot have a DOCTYPE declaration outside of a prolog.

So I moved <!DOCTYPE> to the top, and then I got another message

The name of the top most element must match the name of the DOCTYPE declaration.

Hope you can continue helping me out.

Thanks

08-21-2006, 01:46 PM

domlogic

XML Entities

There are all kinds of "entities" in HTML/XHTML "nbsp" is one of them. You should be able to see that &nbsp; calls this entity and inserts it into a document. With any XML document, you can define your own entities. If the top level element is called <root>, then you can make a simple Doctype declaration without DTD or schema as follows

<xml version="1.0">

<!DOCTYPE root [
<!ENTITY about SYSTEM "path/to/about.xml">
<!ENTITY other SYSTEM "path/to/other.xml">
]>

<root>
&about;
&other;
</root>

adding schema or dtd is also quite simple but what you want to google for is called XML Entities

then when the document is parsed, &about; is replaced with the contents of about.xml
Notice that I haven't used DTD at all here, it is not (really)relevant to your question. I have replaced copyright.dtd with the file to be included (see red). If you want the document to be valid, then you need a schema or dtd for "page" and the included about must also comply with that schema seeing as you are including it in the "page" document. Try without validation first and see the include in effect, then tackle the second problem of validation.

When you get to step 2, your doctype will look similar to this XHTML example:

However, I guess the biggest concern I have re: your approach is actually the source of my problem: if I include the about.xml, does it mean the whole <about> tag will be embedded into this xml file?

Each xml that includes this file has its specific moduleID and this string needs to be displayed in the copyright information too. If you make this a separate about.xml then isn't it now too generic, and I can't change this string from page to page anymore, isn't it?

Thanks, as I said, I'll spend more time into this - I guess this is the learning curve of XML that I have to conquer to really understand all the relationships among entity, doctype, etc. etc.

Thanks

08-21-2006, 05:05 PM

calgarychinese

Hi there, I have somewhat made some more progress.

Now I have my about.xml as suggested earlier. In the module Name section there, I replace that string "mEmployeeDetails" with "&moduleID;"

xdEmp.ParseError.Reason = ""The element 'page' is used but not declared in the DTD/Schema."

So does it mean I still have to provide the DTD for this employee.xml in detail?

Thanks

08-21-2006, 05:36 PM

domlogic

Hi ya

I am glad you have your includes working.

Well, I transform my xml using an xslt which can either be run in the browser or prior to serving, using an xslt processor like xalan or ant task (in my world). Unfortunately while I can help you with including external entities in your DOM tree, I cannot offer you support on the msxml parser or vb script as I don't use them.

It does seem that your parser wants a valid xml file which leaves you with two options.

1. Elect to use a parser which checks for well formedness but not validity (this may be an option with your parser), or

2. Write a schema and declare your document to adhere to it.

Eventually you will have to write a schema or dtd to make your document valid.

I reccomend tackling lots of small problems rather than one big problem. So I would start by writing a schema which has very limited restrictions to appease the parser and then refining your schema to meet the requirements. Other people will reccomend different approaches based on different philosophies.

If you become schema savvy, maybe you can help me with my xsd:key issue which I posted to this forum ;)

Stick with it and good luck :D

08-22-2006, 01:17 PM

calgarychinese

Hi domlogic, thanks for your advice.

I just feel completely defeated. I am encountering some related issues, not sure if you could help too, just cos I think they may not have to do with which parser I use.

So I have this about.xml. I use this code to combine the contents into the resulting HTML file.

dim copyNode
for each node in AboutNode.childNodes
set copyNode = node.Clone()
parentNode.appendchild(copyNode)
next

It is fine except in the resulting html, my entity is not replaced. Remeber I told you there's a place in the <about> that I need to have an entity referencing the module ID?

and inside my about.xml I have something like this:
<span>&moduleID;</span>

but as a result, it gets blanked. There is nothing. I used the debugger and I see something like NodeTypedValue which contains the string "EmployeeName", but then after append the string is gone.

AM I making sense?

Any idea what went wrong? Been over a week since I've been struggling this now... and I thought it would be easy..... :(

Thanks

08-22-2006, 02:13 PM

domlogic

This is starting to look like a problem for xslt or some other programmatic method but this thread topic is about including xml from one file into another. The simple answer to your latest post is that you don't need to attach nodes or do anything with VB except load the "bigger" xml/xhtml file and parse it. So yes, it is already included with those ENTITY statements.

The more complicated answer is that you need some way of changing the content in that file you are including, so this is not the best method. You probably want to make the html file and convert it into an xslt. Then you have an xml file which has the moduleID and other variable data.