Is there any difference between 'valid xml' and 'well formed xml'?

前端 未结 14 2746
清酒与你
清酒与你 2020-11-21 04:43

I wasn\'t aware of a difference, but a coworker says there is, although he can\'t back it up. What\'s the difference if any?

相关标签:
14条回答
  • 2020-11-21 05:42

    See XML DTD on W3 Schools:

    An XML document with correct syntax is called "Well Formed".

    An XML document validated against a DTD is both "Well Formed" and "Valid".

    0 讨论(0)
  • 2020-11-21 05:43

    In addition to the aforementioned DTD's, there are 2 other ways of describing and validating XML documents are XMLSchema and RelaxNG, both of which may be easier to use and support more features than DTD.

    0 讨论(0)
  • 2020-11-21 05:43

    If XML is confirming to DTD rules then it's a valid XML. If a XML document is conforming to XML rules (all tags started are closed,there is a root element etc)then it's a well formed XML.

    0 讨论(0)
  • 2020-11-21 05:45

    Well-Formed XML is XML that meets the syntactic requirements of the language. Not missing any closing tags, having all your singleton tags use <whatever /> instead of just <whatever>, and having your closing tags in the right order.

    Valid XML is XML that uses a DTD and complies with all its requirements. So if you use an attribute improperly, you violate the DTD and aren't valid.

    All valid XML is well-formed, but not all well-formed XML is valid.

    0 讨论(0)
  • 2020-11-21 05:48

    Valid XML is XML that succeeds validation against a DTD.

    Well formed XML is XML that has all tags closed in the proper order and, if it has a declaration, it has it first thing in the file with the proper attributes.

    In other words, validity refers to semantics, well-formedness refers to syntax.

    So you can have invalid well formed XML.

    0 讨论(0)
  • 2020-11-21 05:48

    Well, XML that isn't well formed, sort of by definition, isn't XML. Poeple usually refer to valid XML as XML that adheres to a certain schema (XSD or DTD).

    0 讨论(0)
提交回复
热议问题