Recent posts

Recent comments

Archive

Calender

«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

출처 : w3schools - XML Attributes(영문)


위 사이트의 내용을, 내맘대로 해석함. ─.─;;


XML elements can have attributes, just like HTML. Attributes provide additional information about an element.


HTML에서처럼, XML 엘리먼트는 속성을 가질 수 있다. 속성은 엘리먼트에 관한 추가 정보를 제공한다.


XML Attributes

XML의 속성


In HTML, attributes provide additional information about elements:
HTML에서, 속성은 엘리먼트에 대한 추가 정보를 제공한다.

 
<img src="computer.gif">
<a href="demo.asp">
 

Attributes often provide information that is not a part of the data.
In the example below, the file type is irrelevant to the data,
but can be important to the software that wants to manipulate the element:


속성은, 데이터의 일부가 아닌 정보를, 제공하기도 한다.
아래 예문에서, 파일의 타입은 데이터와 직접적인 관계는 없다.
하지만 엘리먼트를 다루거나 처리하려는 소프트웨어에게는 중요한 정보일 수 있다.


 
<file type="gif">computer.gif</file>
 

XML Attributes Must be Quoted

XML의 속성은 인용되어야 한다. (따옴표로 감싸져야 한다)


Attribute values must always be quoted. Either single or double quotes can be used.
속성들은 반드시 인용되어야 한다. 작은따옴표나 큰따옴표 중에서 하나를 사용할 수 있다.


 
<person gender="female">

또는 

<person gender='female'>
 

If the attribute value itself contains double quotes you can use single quotes, like in this example:
속성값 자체에 큰따옴표가 들어갈 경우, 아래 예문처럼 작은따옴표를 사용할 수 있다.

 
<gangster name='George "Shotgun" Ziegler'>
 

or you can use character entities:
또는, 문자 참조(character entity)를 사용해도 된다.

 
<gangster name="George &quot;Shotgun&quot; Ziegler">
 

XML Elements vs. Attributes

XML의 엘리먼트와 속성의 차이


 
<person gender="female">
	 <firstname>Anna</firstname>
	 <lastname>Smith</lastname>
</person>
 
 
<person>
	 <gender>female</gender>
	 <firstname>Anna</firstname>
	 <lastname>Smith</lastname>
</person>
 

In the first example gender is an attribute. In the last, gender is an element.
Both examples provide the same information.

첫번째 예문에서 gender는 속성이다. 그 다음 예문에서 gender는 엘리먼트이다.
두 예문 모두 같은 정보를 제공하고 있다.


There are no rules about when to use attributes or when to use elements.
Attributes are handy in HTML.
In XML my advice is to avoid them. Use elements instead.


속성을 사용할 때와 엘리먼트를 사용할 때에 대해서, 따로 정해진 규칙은 없다.
HTML에서는 속성이 더 사용하기 편하다.
XML에 대한 나의 충고는, 속성은 피하고, 대신에 엘리먼트를 사용하라는 것이다.


My Favorite Way

내가 자주 쓰는 방법


The following three XML documents contain exactly the same information:
아래 세 개의 XML 문서는 정확히 똑같은 정보를 담고 있다.


1. A date attribute is used in the first example:
date라는 속성으로 지정하는 방법.

 
<note date="2008-01-10">
	 <to>Tove</to>
	 <from>Jani</from>
	 <heading>Reminder</heading>
	 <article>Don't forget me this weekend!</article>
</note>
 

2. A date element is used in the second example:
date라는 엘리먼트로 지정하는 방법.

 
<note>
	 <date>2008-01-10</date>
	 <to>Tove</to>
	 <from>Jani</from>
	 <heading>Reminder</heading>
	 <article>Don't forget me this weekend!</article>
</note>
 

3. An expanded date element is used in the third: (THIS IS MY FAVORITE):
date 엘리먼트를 확장하는 방법. ( 이것이 내가 자주 쓰는 방법이다 )

 
<note>
	 <date>
		 <year>2008</year>
		 <month>01</month>
		 <day>10</day>
	 </date>
	 <to>Tove</to>
	 <from>Jani</from>
	 <heading>Reminder</heading>
	 <article>Don't forget me this weekend!</article>
</note>
 

Avoid XML Attributes?

XML에서 속성을 기피해야 하는가?


Some of the problems with using attributes are:
속성을 사용함에 있어서 문제점이 조금 있다.


  • attributes cannot contain multiple values 속성에는 여러 개의 값을 넣을 수 없다.
  • attributes cannot contain tree structures 속성에는 트리 구조(tree structure)를 넣을 수 없다.
  • attributes are not easily expandable 속성은 쉽사리 확장시킬 수 없다.

엘리먼트에서는 위의 것들이 모두 가능하다.


Attributes are difficult to read and maintain.
Use elements for data.
Use attributes for information that is not relevant to the data.


속성은 읽고 보존하기가 어렵다.
데이터와 관련해서는 엘리먼트를 사용하라.
데이터와 관련이 없는 정보에 대해서는 속성을 사용하라.


Don't end up like this:
(문서 작성을) 아래처럼 끝내지 말아라.

 
<note day="10" month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
article="Don't forget me this weekend!">
</note>
 

XML Attributes for Metadata

메타데이터를 위한 속성


Sometimes ID references are assigned to elements.
때때로 ID reference가 엘리먼트에 할당될 때가 있다.


ID reference :
ID 조회?... ID 참조?... ID 인용?...
이놈의 reference라는 단어는 튀어나올때마다 번역하기가 참... 애매하다....


These IDs can be used to identify XML elements
in much the same way as the id attribute in HTML.

HTML에서의 id 속성과 거의 같은 방식으로,
XML의 엘리먼트들을 구분짓기 위해서 이런 ID들이 사용될 수 있다.

 
<messages>
	 <note id="501">
		 <to>Tove</to>
		 <from>Jani</from>
		 <heading>Reminder</heading>
		 <article>Don't forget me this weekend!</article>
	 </note>
	 <note id="502">
		 <to>Jani</to>
		 <from>Tove</from>
		 <heading>Re: Reminder</heading>
		 <article>I will not</article>
	 </note>
</messages>
 

The id attributes above are for identifying the different notes. It is not a part of the note itself.
위의 id 속성은 각각의 note를 식별하기 위한 것이다. note 자체의 일부가 아니다.


What I'm trying to say here is that metadata (data about data) should be stored as attributes,
and the data itself should be stored as elements.

내가 여기서 말하고자 하는 것은,
(데이터에 관한 데이터인) 메타데이터는 속성으로 저장되어야 하며,
데이터 그 자체는 엘리먼트로 저장되어야 한다는 것이다.




이 글이 도움이 되셨나요? *^^*

'XML > w3schools' 카테고리의 다른 글

[ XML ] 7. XML의 인코딩(Encoding)  (0) 2015.06.24
[ XML ] 6. XML Namespaces  (0) 2015.06.22
[ XML ] 4. XML의 엘리먼트  (0) 2015.06.21
[ XML ] 3. XML 문서에서의 문법  (0) 2015.06.20
[ XML ] 2. XML의 트리 구조  (0) 2015.06.20