XML 네임 스페이스

wwiki
이동: 둘러보기, 검색

개요[편집 | 원본 편집]

태그나 속성에 이름의 중복으로 인한 충돌을 방지하고자 네임스페이스를(일종의 접두사) 사용한다. 충돌방지를 위한 것이므로 고유한 값을 가지는 URI를 사용한다.

<tagName xlmns:prefix="URI">
<prefix: tagName> </prefix: tagName>

네임스페이스 접두사 edi 를 네임스페이스 이름과 연결하는 네임스페이스 선언의 예 http://ecommerce.example.org/schema:
<x xmlns:edi='http://ecommerce.example.org/schema'>
  <!-- "edi" prefix는 "x"의 엘리먼트와 컨텐츠에 대해서 http://ecommerce.example.org/schema에 바인딩 된다.-->
</x>

요소 이름으로 사용되는 규정된 이름의 예:
<!-- the 'price' element의 네임스페이스는 http://ecommerce.example.org/schema 이다.-->
<edi:price xmlns:edi='http://ecommerce.example.org/schema' units='Euro'>32.18</edi:price>
속성 이름으로 사용되는 규정된 이름의 예:
<x xmlns:edi='http://ecommerce.example.org/schema'>
  <!-- the 'taxClass' attribute의 네임스페이스는 http://ecommerce.example.org/schema이다. -->
  <lineItem edi:taxClass="exempt">Baby food</lineItem>
</x>

네임스페이스 범위[편집 | 원본 편집]

하위 태그에서 사용할 수 있다.
<?xml version="1.0"?>
<html:html xmlns:html='http://www.w3.org/1999/xhtml'>
  <html:head><html:title>Frobnostication</html:title></html:head>
  <html:body><html:p>Moved to 
    <html:a href='http://frob.example.com'>here.</html:a></html:p></html:body>
</html:html>
다음의 예와 같이 단일 요소에 여러 네임 스페이스 접두사를 속성으로 선언 할 수있다 :
<?xml version="1.0"?>
<!-- both namespace prefixes are available throughout -->
<bk:book xmlns:bk='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'>
    <bk:title>Cheaper by the Dozen</bk:title>
    <isbn:number>1568491379</isbn:number>
</bk:book>

둘러보기 메뉴