'유효한 XML'과 '잘 형성된 XML'간에 차이점이 있습니까?
나는 차이점을 인식하지 못했지만 동료가 그것을 백업 할 수는 없지만 있다고 말합니다. 차이점이 있다면 무엇입니까?
네, 차이가 있습니다.
XML 표준 을 준수하는 XML 은 올바른 형식으로 간주 되고 DTD 를 준수하는 xml 은 유효한 것으로 간주됩니다.
유효한 XML은 DTD에 대한 유효성 검사에 성공한 XML입니다.
잘 구성된 XML은 모든 태그가 적절한 순서로 닫혀있는 XML이며 선언이있는 경우 파일에 적절한 속성이있는 첫 번째 항목이 있습니다.
즉, 유효성은 의미론을 의미하고 올바른 형식은 구문을 의미합니다.
따라서 잘못된 형식의 XML이있을 수 있습니다.
올바른 형식과 유효한 XML
올바른 형식 이란 텍스트 개체가 XML이되기 위한 W3C 요구 사항 을충족 함을 의미합니다.
유효 함은 올바른 형식의 XML이 지정된 스키마에서 제공하는 추가 요구 사항을 충족 함을 의미합니다.
공식 정의
[정의 : 데이터 객체는 이 사양에 정의 된대로 잘 구성된 경우 XML 문서 입니다. 또한 XML 문서는 특정 추가 제약 조건을 충족하는 경우 유효 합니다.]
관찰 :
- 형식이 올바르지 않은 문서는 XML이 아닙니다. ( 잘 구성된 XML 이 일반적으로 사용되지만 기술적으로 중복됩니다.)
- 유효하다는 것은 잘 구성된 것을 의미합니다.
- 잘 구성되어 있다고해서 타당 함을 의미하지는 않습니다.
- XML에 대한 W3C 권장 사항 은 DTD에 대한 유효성 을 정의 하지만 , 일반적인 사용을 통해 XSD , RELAX NG , Schematron 또는 기타 방법을 통해 지정된 XML 스키마에 대한 적합성을 위해 용어를 적용 할 수 있습니다 .
문서가되는 원인의 예 ...
잘 구성되지 않음 :
- 요소에 닫는 태그가 없습니다 (자동 닫힘이 아님).
- 적절한 중첩없이 요소가 겹칩니다.
<a><b></a></b>
- 속성 값에 여는 따옴표와 일치하는 닫는 따옴표가 없습니다.
<
또는&
내용보다는 사용된다<
나&
.- 여러 루트 요소가 있습니다.
- XML 선언이 여러 개 있거나 XML 선언이 문서 맨 위에 표시되지 않습니다.
유효하지 않음 :
- 요소 또는 속성이 누락되었지만 XML 스키마에 필요합니다.
- 요소 또는 속성이 사용되지만 XML 스키마에 의해 정의되지 않습니다.
- 요소의 내용이 XML 스키마에 지정된 내용과 일치하지 않습니다.
- 속성 값이 XML 스키마에 지정된 유형과 일치하지 않습니다.
잘 구성된 네임 스페이스
기술적으로 XML의 구성 요소 이름에는 콜론 문자가 허용됩니다. 그러나 콜론 은 네임 스페이스 용도로만 이름에 사용해야합니다.
노트 :
XML 권장 사항 [ XML 이름 ] 의 네임 스페이스는 콜론 문자를 포함하는 이름에 의미를 지정합니다. 따라서 작성자는 네임 스페이스 용도를 제외하고 XML 이름에 콜론을 사용해서는 안되지만 XML 프로세서는 콜론을 이름 문자로 허용해야합니다.
따라서 다른 용어 인 namespace- well-formed는 올바른 형식에 대한 모든 XML 규칙 과 함께 해당 네임 스페이스 및 네임 스페이스 접두사를 관리하는 XML 1.0 W3C 권장 사항 의 네임 스페이스에 정의되어 있습니다.
구어 적으로 잘 구성된 용어 는 종종 잘 구성된 네임 스페이스 가 더 정확한 곳에 사용됩니다 . 그러나 이것은이 답변에 설명 된 올바른 형식과 유효한 XML을 구분하는 것보다 덜 실용적인 결과의 사소한 기술적 방식입니다 .
다른 사람들이 말했듯이 올바른 형식의 XML은 XML 사양을 따르고 유효한 XML은 주어진 스키마를 따릅니다.
또 다른 표현은 올바른 형식의 XML은 어휘 적으로 정확하고 (파싱 할 수 있음) 유효한 XML은 문법적으로 정확합니다 (알려진 어휘 및 문법과 일치시킬 수 있음).
XML 문서는 올바른 형식이 될 때까지 유효하지 않습니다. 모든 XML 문서는 올바른 형식을 위해 동일한 표준 (W3에서 제시 한 RFC)을 따릅니다. 하나의 XML 문서는 일부 스키마에 대해 유효하고 다른 스키마에 대해서는 유효하지 않을 수 있습니다. 스키마 언어에는 여러 가지가 있으며 그 중 대부분은 XML 기반입니다.
Well-Formed XML은 언어의 구문 요구 사항을 충족하는 XML입니다. 닫는 태그가 누락되지 않고 모든 싱글 톤 태그가 <whatever />
대신 사용 <whatever>
하고 올바른 순서로 닫는 태그가 있습니다.
유효한 XML은 DTD를 사용하고 모든 요구 사항을 준수하는 XML입니다. 따라서 속성을 부적절하게 사용하면 DTD를 위반하고 유효하지 않습니다.
모든 유효한 XML은 올바른 형식이지만 올바른 형식의 모든 XML이 유효한 것은 아닙니다.
XML은 표준에 의해 설정된 모든 XML 문서에 대한 요구 사항을 충족하는 경우 잘 구성된 것입니다. 즉, 단일 루트 노드가 있고, 노드가 올바르게 중첩되고, 모든 노드에 닫는 태그가 있습니다 (또는 이전에 슬래시의 빈 노드 속기 사용). 닫는 꺾쇠 괄호), 따옴표로 묶인 속성 등. 올바른 형식은 XML 규칙을 준수하고 따라서 제대로 구문 분석 할 수 있음을 의미합니다.
XML은 DTD 또는 스키마에 대해 유효성을 검사하는 경우 유효합니다. 이것은 케이스마다 분명히 다릅니다. 한 스키마에 대해 유효한 XML은 여전히 올바른 형식이지만 다른 스키마에 대해서는 유효하지 않습니다.
If XML isn't well-formed it can't be properly parsed - parsers will simply throw an exception or report an error. This is generic and it doesn't matter what your XML contains. Only once it is parsed can it be checked for validity. This domain or context dependent and requires a DTD or schema to validate against. For simple XML documents, you may not have a DTD or schema, in which case you can't know if the XML is valid - the concept or validity simply doesn't apply in this case. Of course, this doesn't mean you can't use it, it just means you can't tell whether or not it's valid.
W3C, in the XML specification, has defined certain rules that needs to be followed while creating XML documents. The examples of such rules include having exactly one root element, having end-tag for each start-tag, using single/double quotes for attribute values, and so on. If an XML document follows all these rules, it is said to be well-formed document and XML parsers can be used to parse and process such documents.
Document Type Definitions (DTDs) or XML Schemas can be used to define the structure and content of a specific class of XML documents. This includes the parent-child relationship details, attribute lists, data type information, value restrictions, etc. In addition to the well-formedness rules, if an XML document also follows the rules specified in the associated DTD/Schema, it is said to be a valid XML document.
All valid XML documents are well-formed, but the reverse is not always true. Well-formed XML documents do not necessarily have to be valid.
I'll add that valid XML also implies that it's well-formed, but well-formed XML is not necessarily valid.
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.
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.
Taken from Extensible Markup Language (XML) 1.0 (Fifth Edition) - W3C Recommendation 26 November 2008 :
[Definition: A data object is an XML document if it is well-formed, as defined in this specification. In addition, the XML document is valid if it meets certain further constraints.]
For those who prefer psuedo-code to paragraphs upon paragraphs of text... :)
IF is_well_formed(<XML_doc>) THEN
# It is well-formed, and can be parsed
IF is_valid(<XML_doc>) THEN
# Well-formed and ALSO valid. Hurray!
# **A valid XML doc, is a well-formed doc!**
ELSE
# Only well-formed, NOT valid
END IF
ELSE
# Not well-formed, or valid!
END IF
FUNCTION is_well_formed
IF <does_not_contain_syntax,_spelling,_punctuation,_grammar_errors,_etc._errors> THEN
RETURN TRUE
ELSE
RETURN FALSE
END IF
END FUNCTION
FUNCTION is_valid
IF <markup_of_the_XML_document_matches_"some"_defined_standard> THEN
# Standards used to validate XML could be a DTDs or XML Schemas, referenced within the XML document
RETURN TRUE
ELSE
RETURN FALSE
END IF
END FUNCTION
Based on the theory: "Well Formed" vs. Valid
DTD is the acronym for Document Type Definition. This is a description of the content for a family of XML files. This is part of the XML 1.0 specification, and allows one to describe and verify that a given document instance conforms to the set of rules detailing its structure and content.
Validation is the process of checking a document against a DTD (more generally against a set of construction rules).
The validation process and building DTDs are the two most difficult parts of the XML life cycle. Briefly a DTD defines all the possible elements to be found within your document, what is the formal shape of your document tree (by defining the allowed content of an element; either text, a regular expression for the allowed list of children, or mixed content i.e. both text and children). The DTD also defines the valid attributes for all elements and the types of those attributes.
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).
An XML document with correct syntax is called "Well Formed".
An XML document validated against a DTD is both "Well Formed" and "Valid".
'Nice programing' 카테고리의 다른 글
계수 나누기 (%)가 정수에서만 작동하는 이유는 무엇입니까? (0) | 2020.10.18 |
---|---|
팬더 데이터 프레임 예쁜 인쇄 (0) | 2020.10.18 |
정규식 자바 스크립트에서 물음표 이스케이프 (0) | 2020.10.18 |
SPAN의 높이 속성을 설정하는 방법 (0) | 2020.10.18 |
NoSQL 데이터베이스를 사용하는 전자 상거래 웹 사이트가 있습니까? (0) | 2020.10.18 |