null XML 요소를 나타내는 올바른 방법은 무엇입니까?
null
여러 가지 방법으로 표현 된 요소를 보았습니다 .
요소는 다음과 같이 존재합니다 xsi:nil="true"
:
<book>
<title>Beowulf</title>
<author xsi:nil="true"/>
</book>
요소가 존재하지만 빈 요소로 표시됩니다 ( '빈'으로 잘못되어 null
의미 상 다른 것으로 생각합니다).
<book>
<title>Beowulf</title>
<author/>
</book>
<!-- or: -->
<book>
<title>Beowulf</title>
<author></author>
</book>
요소가 반환 된 마크 업에 전혀 존재하지 않습니다 .
<book>
<title>Beowulf</title>
</book>
요소에는 <null/>
하위 요소가 있습니다 ( 아래 TStamper 에서 ).
<book>
<title>Beowulf</title>
<author><null/></author>
</book>
그러한 null
가치 를 표현하는 올바른 방법 또는 정식적인 방법이 있습니까? 위의 예보다 추가 방법이 있습니까?
위 예제의 XML은 고안되었으므로 너무 많이 읽지 마십시오. :)
xsi : nil은 다음과 같은 값을 나타내는 올바른 방법입니다. DOM 레벨 2 호출 getElementValue ()가 발행 될 때 NULL 값이 리턴됩니다. xsi : nil은 또한 내용 유형이 일반적으로 빈 요소를 허용하지 않는 경우에도 내용이없는 유효한 요소를 나타내는 데 사용됩니다.
빈 태그를 사용하면 getElementValue ()는 빈 문자열 ( "")을 반환합니다. 태그를 생략하면 작성자 태그도 존재하지 않습니다. 이는 'nil'로 설정하는 것과 의미 상 다를 수 있습니다 (예 : "Series"를 nil로 설정하면 책이 시리즈에 속하지 않을 수 있지만 시리즈를 생략하면 시리즈가 현재 요소에 적용 할 수없는 요소임을 의미 할 수 있습니다.)
보낸 사람 : W3C
XML Schema : Structures는 컨텐츠가 비어 있거나 컨텐츠를 허용하지 않아도되는 컨텐츠 유형에도 불구하고 엘리먼트가 컨텐츠가 없을 때 엘리먼트가 유효하다고 받아 들여 져야한다는 신호 전달 메커니즘을 소개합니다. 속성 값이 true 인 xsi : nil 속성을 가진 요소는 내용없이 유효 할 수 있습니다. 레이블이 지정된 요소는 비어 있어야하지만 해당 복합 유형에 의해 허용되는 경우 속성을 가질 수 있습니다.
설명 :
book xml 요소가 있고 자식 요소 중 하나가 book : series 인 경우 채울 때 몇 가지 옵션이 있습니다.
- 요소 전체 제거-시리즈에이 책이 적용되지 않거나 해당 책이 시리즈의 일부가 아님을 나타내려면 수행 할 수 있습니다. 이 경우 book : series와 일치하는 템플릿이있는 xsl 변환 (또는 다른 이벤트 기반 프로세서)은 호출되지 않습니다. 예를 들어, xsl이 책 요소를 테이블 행 (xhtml : tr)으로 바꾸면이 방법을 사용하여 잘못된 수의 테이블 셀 (xhtml : td)을 얻을 수 있습니다.
- 요소를 비워 두는 경우-시리즈가 ""이거나 알 수 없거나 책이 시리즈의 일부가 아님을 나타낼 수 있습니다. book : series와 일치하는 모든 xsl 변환 (또는 다른 기본 기반 파서)이 호출됩니다. current ()의 값은 ""입니다. 이 방법을 사용하면 다음에 설명하는 것과 같은 수의 xhtml : td 태그를 얻을 수 있습니다.
- xsi : nil = "true"사용-이것은 book : series 요소가 비어있는 것이 아니라 NULL임을 나타냅니다. book : series와 템플릿이 일치하는 xsl 변환 (또는 다른 이벤트 기반 파서)이 호출됩니다. current ()의 값은 비어 있습니다 (빈 문자열 아님). 이 방법과 (2)의 주요 차이점은 book : series 스키마 유형이 빈 문자열 ( "")을 유효한 값으로 허용 할 필요가 없다는 것입니다. 이것은 직렬 요소에는 의미가 없지만 스키마에서 열거 된 유형으로 정의 된 언어 요소에 대해서는 xsi : nil = "true"를 사용하여 요소에 데이터가 없어도됩니다. 다른 예는 10 진수 유형의 요소입니다. 비워 두려면 ""와 10 진수 만 허용하는 열거 된 문자열을 결합하거나 닐 가능한 10 진수를 사용할 수 있습니다.
XML에는 근본적으로 null 개념이 없기 때문에 정식 답변이 없습니다. 그러나 객체 그래프에 null이 있기 때문에 Xml / Object 매핑을 원한다고 가정합니다. 따라서 당신의 대답은 "도구가 무엇을 사용하든"입니다. 핸들링을 쓰면 원하는 것을 의미합니다. XML 스키마를 사용하는 도구의 xsi:nil
경우가는 길입니다. 대부분의 매퍼의 경우 일치하는 요소 / 속성을 생략하는 것이 좋습니다.
XML의 유효성을 검사하는 방법에 따라 다릅니다. XML 스키마 유효성 검사를 사용하는 경우 올바른 null
값 표현 방법은 xsi:nil
속성을 사용하는 것입니다.
[ 출처 ]
w3 링크의 문서
http://www.w3.org/TR/REC-xml/#sec-starttags
이것이 권장되는 양식이라고 말합니다.
<test></test>
<test/>
The attribute mentioned in the other answer is validation mechanism and not a representation of state. Please refer to the http://www.w3.org/TR/xmlschema-1/#xsi_nil
XML Schema: Structures introduces a mechanism for signaling that an element should be accepted as ·valid· when it has no content despite a content type which does not require or even necessarily allow empty content. An element may be ·valid· without content if it has the attribute xsi:nil with the value true. An element so labeled must be empty, but can carry attributes if permitted by the corresponding complex type.
To clarify this answer: Content
<Book>
<!--Invalid construct since the element attribute xsi:nil="true" signal that the element must be empty-->
<BuildAttributes HardCover="true" Glued="true" xsi:nil="true">
<anotherAttribute name="Color">Blue</anotherAttribute>
</BuildAttributes>
<Index></Index>
<pages>
<page pageNumber="1">Content</page>
</pages>
<!--Missing ISBN number could be confusing and misguiding since its not present-->
</Book>
</Books>
You use xsi:nil
when your schema semantics indicate that an element has a default value, and that the default value should be used if the element isn't present. I have to assume that there are smart people to whom the preceding sentence is not a self-evidently terrible idea, but it sounds like nine kinds of bad to me. Every XML format I've ever worked with represents null values by omitting the element. (Or attribute, and good luck marking an attribute with xsi:nil
.)
Simply omitting the attribute or element works well in less formal data.
If you need more sophisticated information, the GML schemas add the attribute nilReason, eg: in GeoSciML:
xsi:nil
with a value of "true" is used to indicate that no value is availablenilReason
may be used to record additional information for missing values; this may be one of the standard GML reasons (missing, inapplicable, withheld, unknown
), or text prepended byother:
, or may be a URI link to a more detailed explanation.
When you are exchanging data, the role for which XML is commonly used, data sent to one recipient or for a given purpose may have content obscured that would be available to someone else who paid or had different authentication. Knowing the reason why content was missing can be very important.
Scientists also are concerned with why information is missing. For example, if it was dropped for quality reasons, they may want to see the original bad data.
In many cases the purpose of a Null value is to serve for a data value that was not present in a previous version of your application.
So say you have an xml file from your application "ReportMaster" version 1.
Now in ReportMaster version 2 a some more attributes have been added that may or not be defined.
If you use the 'no tag means null' representation you get automatic backward compatibility for reading your ReportMaster 1 xml file.
참고URL : https://stackoverflow.com/questions/774192/what-is-the-correct-way-to-represent-null-xml-elements
'Programming' 카테고리의 다른 글
배포 할 Android Jar 라이브러리 만들기 (0) | 2020.06.03 |
---|---|
이것을 이해하도록 도와 줄 수 있습니까? (0) | 2020.06.03 |
작동하는 C ++ 리팩토링 도구가 있습니까? (0) | 2020.06.03 |
.vcxproj.filter 파일을 소스 제어에 추가해야합니까? (0) | 2020.06.03 |
node.js 대 ASP.NET Core 성능 테스트의 예기치 않은 결과 (0) | 2020.06.03 |