Forum How do I...?

Loose (x)includes?

Infarinato
Hi again. :) In my attempt to get JavaScript to automatically generate a table of contents for a collection of [randomly selected] web pages (which I’m now quite happy about :D, and will soon publish the outcome to this forum for whoever might be interested), I’ve come to realize that my approach might actually fail in a number of instances. :?

Our web pages should all be XHTML 1.0 Strict (and mostly are), but unfortunately on one hand content editors seem to find always new ways to bypass our web content management validation enforcement routines, on the other hand sometimes “non-quite-compliant” external feeds inject the odd unescaped ampersand, and so on…

So, I guess my question is: is there a way to…

  1. either “relax” the XML validation on the XIncluded files;
  2. or make JavaScript see as a “single document” a list of HTML files supplied in the command line with “-i html”.

I tried hard to achieve (2), but couldn’t really find a way to reliably access the DOM of the combined file with JavaScript, paginate it or link from the TOC page to its targets. That’s why I eventually resorted to the XInclude approach, which is great and gives me exactly what I wanted… if it wasn’t for that [strict] XML validation “drawback”.

Many thanks.
mikeday
As far as I can tell neither of these is quite possible yet, but option 2. may be possible in the future. XInclude is strictly XML-only, and there is no way to invoke the HTML parser for an included subdocument. In future we will be looking into providing a JavaScript API for accessing more than one document.
Infarinato
Thank you for getting back to me on this one, Mike.

Eventually we managed to overcome the “limitations” of (1) by falling back to a “URL tidifier”, based on HTML Tidy (currently using the PHP extension, but ultimately the corresponding .NET library as part of the same .NET web service/application we invoke Prince from), e.g.:
<xi:include href="http://www.mysubdomain.mydomain.com/a-dodgy-page" xml:base="http://www.mydomain.com/">
	<xi:fallback>
		<xi:include href="http://www.mydomain.com/tidy.php?url=http%3A//www.mysubdomain.mydomain.com/a-dodgy-page" xml:base="http://www.mydomain.com/">
			<xi:fallback>
				<xi:include href="http://www.mydomain.com/beyond-repair-fallback.html" xml:base="http://www.mydomain.com/"/>
			</xi:fallback>
		</xi:include>
	</xi:fallback>
</xi:include>
:D
mikeday
Nice, creative use of fallbacks there. :)