How to insert XUL into a XHTML document
Asked Answered
K

1

5

I have a XHTML document and want to embed XUL widgets into the document. What is the correct XML syntax to do so?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
</head>
  <body>    
  insert XUL here
  </body>
</html>
Kensell answered 19/10, 2009 at 12:12 Comment(0)
X
10

add xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" to your <html> tag.

then use <xul:element>, e.g. <xul:vbox>

Edit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
</head>
  <body>    
    <xul:vbox>
    </xul:vbox>
  </body>
</html>

Also, I assume this isn't such a simple case... otherwise there wouldn't be much point in wrapping the xul in html (though the other way around does happen sometimes)

Edit

Some additional points to keep in mind when doing this:

  1. must be served with a valid xml type. e.g. application/xml or text/xml -- not text/html. (See https://bugzilla.mozilla.org/show_bug.cgi?id=101147#c12 -- the whole thread is worth a read)
  2. must be valid xml. A certain degree of sloppiness is tolerated by browsers when parsing html (unclosed tags, etc.) and this is not that case for a document containing xul (even the html parts of the document)

(thanks to Nikolay for the first point)

Xenophobe answered 19/10, 2009 at 12:28 Comment(4)
This is correct, although this will only work in "real" XML (i.e. served with an XML content-type, not text/html) and there are many known issues when things don't work right when embedding XUL elements in non-XUL documents.Checkrein
True, Nickolay. Not least among them that it applies to a pretty limited subset of browsers. I'll add your points to the answer. Good to have your expertise here.Xenophobe
Clarification: my last point was specific to Mozilla. XUL elements are usually not used outside XUL documents in Firefox, so these uses are mostly untested and there are bugs with XUL in non-XUL documents, e.g.: bugzilla.mozilla.org/show_bug.cgi?id=101147#c12Checkrein
Works perfectly. My use case is of course a little bit more complex.Kensell

© 2022 - 2024 — McMap. All rights reserved.