1

I have a document in XHTML5. That just means that I'm creating an HTML5 document, but I want all the ending tags to be present and I want appropriate encoding, etc. So the file extension is xhtml and the file starts with:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html lang="en-us" xmlns="http://www.w3.org/1999/xhtml">

All this is completely standard stuff. Just simple HTML5 encoded in XML.

I installed jEdit 5.3.0 with the XML Sidekick plugin. Immediately I get an error list, saying:

Element type "html" must be declared.
Element type "html" must be declared.
Element type "body" must be declared.
Element type "h1" must be declared.
Element type "p" must be declared.
...

The Sidekick outline looks cool, and the popup suggesting the element and attribute names is nice.

But how do I get rid of all those errors? I don't need or want a DTD.

If I change the parser to html then I don't get any errors --- but I don't get any DOM tree representation or auto-suggest either.

Why doesn't jEdit+Sidekick like my simple, standards-compliant XHTML5 file?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • Not directly related to your question, so I didn't address this point in my answer... are you serving that document over HTTP(S) as media type `text/html` or `application/xhtml+xml`? – Graham Hannington Feb 12 '16 at 07:32
  • 1
    If you're no longer interested in an answer to this question because you have found a different editor that does as-you-type validation of XHTML5, I'd be interested in what you're using, especially if it's free. I use several commercial validating XML editors, and I occasionally look around at what's new, but I keep coming back to jEdit. – Graham Hannington Feb 18 '16 at 08:16

2 Answers2

1

Re:

But how do I get rid of all those errors?

This answer describes one way. There are others.

Re:

Why doesn't jEdit+Sidekick like my simple, standards-compliant XHTML5 file?

<!DOCTYPE html> triggers jEdit's DTD-based parsing, but doesn't provide enough information to locate a corresponding DTD. For details, see the description of "permitted-public-ID-system-ID-combination" on the W3C web page "HTML syntax".

Re:

I don't need or want a DTD.

If you want to validate XHTML5 in jEdit using the XML plugin, then you need either a DTD or a schema. This answer uses a W3C XML schema.

If you only want to check that your XHTML5 is well-formed, but not necessarily valid, then, yes, as you say, you don't need either a DTD or a schema, and you can ignore most of this answer: just insert the string :xml.validate.ignore-dtd=true: in a comment in one of the top 10 lines of your XHTML5 document.

Validating XHTML5 in jEdit

Summary

  1. Insert :xml.validate.ignore-dtd=true: in a comment in the first 10 lines of your XHTML5 to prevent jEdit DTD parsing.
  2. Download an XHTML5 schema.
  3. In jEdit, associate the XHTML5 schema with your XHTML5 document.

Detailed procedure

The following procedure assumes that you have already installed jEdit with the XML plugin.

  1. Insert the string :xml.validate.ignore-dtd=true: in a comment in the first 10 lines of your XHTML5 file. For example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <!-- jEdit XML plugin property: :xml.validate.ignore-dtd=true: -->
    <meta charset="UTF-8"/>
    <title>XHTML5 document</title>
    </head>
    <body>
    <p>Hello, World!</p>
    </body>
    </html>    
    

    This stops jEdit looking for that nonexistent DTD.

  2. Download the XHTML5 schema from the GitHub repository arasix/XHTML5-XML-Schema.

    Note the caveat in the repository readme about data-* attributes.

    Other schemas for XHTML5 are also available. There is no "official" XHTML5 schema.

  3. Extract the repository .zip file to the location of your choice.
  4. In jEdit, set the schema for your XHTML5 document:
    1. Select Plugins > XML > Set Schema...
    2. Choose the xhtml5_with_microdata.xsd file from the downloaded repository.
    3. I also chose to click "make this location relative (preview bellow)" (sic).

jEdit creates a schemas.xml file in the same directory as your XHTML5 document. For details on schemas.xml, including editing it so that you do not need to set the schema for each of your XHTML5 documents, see the jEdit XML plugin help.

Known issues

Unique particle attribution violations in the schema

When jEdit loads the schema (it does this once, and then caches it), it reports the following errors in xhtml5.xsd:

159:cos-nonambig: "http://www.w3.org/1999/xhtml":link and "http://www.w3.org/1999/xhtml":link (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.

550:cos-nonambig: "http://www.w3.org/1999/xhtml":figcaption and "http://www.w3.org/1999/xhtml":figcaption (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.

I have reported these errors to the schema author.

In practice, you can ignore these errors: in the Error List pane, click the broom ("Clear Error List") button.

After clearing those errors, I found that I needed to "wake up" the XML parsing for my XHTML5 document: select Plugins > Sidekick > Parse Buffer. Then the parse on keystroke starts working again.

No support for HTML named character references

HTML defines various named character references, such as &nbsp; (non-breaking space).

The XML schema-based validation described in this answer does not support such named references, except for those predefined in XML.

For example, entering &nsbp; in your XHTML5 document will generate the following error in jEdit:

The entity "nbsp" was referenced, but not declared.

As a workaround, specify the corresponding XML decimal or hexadecmal numeric character reference: &#160; or &#xA0;.

Troubleshooting

If jEdit does not appear to be parsing your document as XML:

  1. Check that the edit mode of your XHTML5 is xml (that it has not reverted to, say, html): select Utilities > Buffer Options > Edit mode: xml.
  2. "Wake up" XML parsing: select Plugins > Sidekick > Parse Buffer

Questions

Why not just remove the DOCTYPE?

Rather than inserting a jEdit-specific string into my XHTML5 source to prevent DTD-based parsing, why not just remove the DOCTYPE?

There are several reasons: for instance, triggering standards mode in web browsers. For more information, see the WHATWG FAQ; specifically, the answer to the question "What is the DOCTYPE for modern HTML documents?"

Graham Hannington
  • 1,749
  • 16
  • 18
  • A better solution would be to use the RELAX NG schema supplied with the Nu Html Checker (v.Nu). But I'm having trouble getting jEdit to recognize the datatype library from v.Nu. If I can do that, I'll add the details to this answer. – Graham Hannington Feb 22 '16 at 05:21
  • 1
    With help from others, I'm now using a pre-release version of the jEdit XML plugin (containing the required datatype library) to edit XHTML5. For details, see: https://github.com/unsoup/validator – Graham Hannington Mar 10 '16 at 08:05
0

You just have to update your XML plugin. The current version recognizes the HTML5 Doctype declaration and switches to DTD-less validation and completion automatically.

Vampire
  • 35,631
  • 4
  • 76
  • 102