3

XML is a subset of SGML. A valid XML document is also a valid SGML document, but the vice versa isn't true.

Does this keep true even if I use the XML Schema instead of the DTD?

The doubt stems from that fact that the XML DTD is a subset of the SGML DTD, but the XML Schema allows things that can't be defined in the XML DTD.

So is XML Schema still a subset? Can I do with SGML DTD everything I can do with XML Schema?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
zer0uno
  • 7,521
  • 13
  • 57
  • 86
  • Existing questions with detailed comparisons of the expressive power of XSD and DTDs include http://stackoverflow.com/questions/1544200, http://stackoverflow.com/questions/2389760, and http://stackoverflow.com/questions/19683429. The comparisons given are unaffected by the differences between SGML DTDs and XML DTDs. – C. M. Sperberg-McQueen Apr 10 '16 at 18:25

1 Answers1

2

Is XML Schema a subset of SGML DTD?

No, XML Schema is far from being a subset of DTD. XML Schema uses a completely different syntax than DTD, and XML Schema can express many constraints not possible in DTD.

A valid XML document is also a valid SGML document

You probably mean well-formed, not valid. Well-formed is not the same as valid. Here is probably where you want to make a subset statement. XML was designed to be a subset of SGML, yes.

Can I do with SGML DTD everything I can do with XML Schema?

No, not even close. For just one example, DTDs cannot restrict data to numeric types, but XML Schema can trivially. XML Schema in general is far more expressive than DTD.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • How can a valid XML document (using a DTD) not to be a valid SGML document? – zer0uno Mar 16 '16 at 19:02
  • 1
    Either you've misunderstood my answer, or you're still not being careful to distinguish between [valid vs well-formed](http://stackoverflow.com/a/25830482/290085). Either way, **XML being a subset of SGML does not imply that XML Schema is a subset of SGML DTD.** Learn the difference between [*valid* and *well-formed*](http://stackoverflow.com/a/25830482/290085); it'll greatly help your understanding here. – kjhughes Mar 16 '16 at 19:22
  • I undestood the difference between valid and well-formed. I'll try to turn turn the question. Does the XML DTD have "commands" that the SGML DTD doesn't have? – zer0uno Mar 16 '16 at 19:25
  • 1
    Now you're asking a completely different question (with unclear ties to your other lines of query regarding XML Schema); see [**Comparison of SGML and XML**](https://www.w3.org/TR/NOTE-sgml-xml.html) for an overview of the differences between SGML and XML. – kjhughes Mar 16 '16 at 19:38
  • You do realize that [**DTD**](https://www.w3.org/TR/REC-xml/#sec-prolog-dtd) as defined in the [XML Recommendation](https://www.w3.org/TR/REC-xml/) is not the same as [**XML Schema**](https://www.w3.org/TR/xmlschema-1/) (aka XSD), right? – kjhughes Mar 16 '16 at 19:45
  • I know they are different. Maybe this article can help explain what I mean http://www.differencebetween.net/technology/difference-between-sgml-and-xml/. It says "since XML is simply a subset of SGML, SGML parsers are capable of reading and decoding valid XML files. The reverse is not necessarily true though as SGML files might have features that the XML parser does not understand." – zer0uno Mar 16 '16 at 20:54
  • Yes, that's true, and I hope I've provided sufficient background for you to appreciate the difference between the statement you quote and the question you ask in your title. Good luck. – kjhughes Mar 16 '16 at 21:32
  • I think I didn't explain myself well. I understood that XML schema is not a subset of SGML DTD. What I'm asking now is different. Let's suppose XML schema didn't exist, let's forget it for a while. If I wrote a well-formed XML document and conforming to a XML DTD, would it be valid as SGML document? – zer0uno Mar 16 '16 at 22:51
  • Yes. "[The Extensible Markup Language (XML) is a subset of SGML...](https://www.w3.org/TR/REC-xml/)" is, in fact, the opening line of the W3C XML Recommendation. – kjhughes Mar 16 '16 at 23:19