너무 자세하게 설명하지 않고 우리는 XML을 메타 데이터로 사용하여 속성에 대한 제약 조건을 설명하고자합니다 (이것은 축소 된 예이며 XSD는 제안 된 복잡한 모델을 지원하지 않았습니다). 두 가지 옵션이 고려됩니다. 다음 XML 구조는 더 합리적인가?어떤 XML 구조가 더 합리적입니까?
옵션 1)
<?xml version="1.0" encoding="us-ascii"?>
<Properties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Property type="string">
<name>quanitity</name>
<contraints>
<contraint type="isRequired">
<value>true</value>
</contraint>
<contraint type="regex">
<value>^[0-9]$</value>
</contraint>
<contraint type="regex">
<value>^[a-zA-Z]$</value>
</contraint>
</contraints>
</Property>
</Properties>
옵션 2) 유연성을
<?xml version="1.0" encoding="us-ascii"?>
<Properties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Property type="string">
<name>quantity</name>
<IsRequired>true</IsRequired>
<Regex>^[0-9]$</Regex>
<Regex>^[a-zA-Z]$</Regex>
</Property>
</Properties>
"값"태그가 필요하지 않습니다. 하지만 포함하는 요소를 선언하면 형식이 XML의 더 나은 "OO"느낌을 허용합니다. –
새 자식 요소를 추가하기 위해 XML 레이아웃을 재정의하지 않고 나중에 더 추가 할 수 있습니다. –
실제로 이것을 단점으로 간주합니다. 즉, XML 유효성 검사를 통과하지만 파서 코드가 폭발하는 새 제한 조건 값을 쉽게 전달할 수 있습니다. – Adamski