컴퓨터 공부/번역

4. XML 구문 규칙

려리군 2009. 5. 13. 01:29

XML Syntax Rules
XML 구문 규칙


The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
XML의 구문 규칙은 매우 간단하고 논리적이다. 규칙들은 사용하기 쉽고 배우기 쉽다.


All XML Elements Must Have a Closing Tag
모든 XML 엘레먼트들은 닫는 태그를 가져야 한다.

In HTML, you will often see elements that don't have a closing tag:
HTML에서 당신은 닫는 태그를 가지지 않는 엘레먼트들을 자주 볼 수 있을 것이다.


<p>This is a paragraph
<p>This is another paragraph


In XML, it is illegal to omit the closing tag. All elements must have a closing tag:
XML에서 닫는 태그를 생략하는 것은 불법이다. 모든 엘레먼트들은 닫는 태그를
반드시 가져야 한다.


<p>This is a paragraph</p>
<p>This is another paragraph</p>


Note: You might have noticed from the previous example that the XML declaration did not have a closing tag. This is not an error. The declaration is not a part of the XML document itself, and it has no closing tag.
주석: 당신은 XML 선언이 닫는 태그를 가지지 않는다는 것을 이전 예제로부터 알았을 것이다. 이는 오류가 아니다. 선언은 XML 문서 자체의 부분이 아니며 닫는 태그를 가지지 않는다.


XML Tags are Case Sensitive
XML 태그들은 대소문자를 구분한다.

XML elements are defined using XML tags.
XML 엘레먼트들은 XML 태그들을 사용하여 정의된다.

XML tags are case sensitive. With XML, the tag <Letter> is different from the tag <letter>.
XML 태그들은 대소문자를 구분한다. XML에서 태그 <Letter>는 태그 <letter>와 다르다.

Opening and closing tags must be written with the same case:
여는 태그와 닫는 태그는 같은 대소문자로 쓰여져야 한다.


<Message>This is incorrect</message>
<message>This is correct</message>


Note: "Opening and closing tags" are often referred to as "Start and end tags". Use whatever you prefer. It is exactly the same thing.


XML Elements Must be Properly Nested
XML 엘레먼트들은 적절히 포함(내포)되어야 한다.

In HTML, you might see improperly nested elements:
HTML에서 당신은 부적절하게 포함된 엘레먼트들을 볼 수 있을 것이다.


<b><i>This text is bold and italic</b></i>

In XML, all elements must be properly nested within each other:
XML에서 모든 엘레먼트들은
반드시 서로 적절히 포함되어야 한다.


<b><i>This text is bold and italic</i></b>

In the example above, "Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element.
위의 예제에서 적절한 포함은 엘레먼트 <i>는 <b> 엘레먼트 안에 있기 때문에 <b> 엘레먼트 안에 <i>는 닫혀 있어야 한다.


XML Documents Must Have a Root Element
XML 문서는 루트 엘레먼트를 가져야 한다.

XML documents must contain one element that is the parent of all other elements. This element is called the root element.
XML 문서는 모든 다른 엘레먼트의
부모인 하나의 엘레먼트를 가져야 한다. 이 엘레먼트는 루트 엘레먼트라고 부른다.


<root>
<child>
<subchild>.....</subchild>
</child>
</root>


XML Attribute Values Must be Quoted XML 

속성(어트리뷰트) 값들은 따옴표 안에 들어가야 한다.

XML elements can have attributes in name/value pairs just like in HTML.
XML 엘레먼트들은 HTML에서처럼 이름/값 짝에 해당하는 속성(어트리뷰트)을 가진다.

In XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct:
XML에서 속성 값들은 따옴표 안에 들어가야 한다. 아래의 두 XML 문서를 자세히 보아라. 첫번째 것은 틀렸고 두번째 것은 맞다.


<note date=12/11/2007>
<to>Tove</to>
<from>Jani</from>
</note>

<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>

The error in the first document is that the date attribute in the note element is not quoted.
첫번째 문서의 오류는 노트(note)의 날짜(date) 속성이 따옴표 안에 있지 않다는 것이다.


Entity References
개체 참조

Some characters have a special meaning in XML.
몇 문자들은 XML에서 특별한 의미를 가진다.

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
XML 엘레먼트 안에서 <b>같은 문자가 있다면 파서는 이를 새로운 요소의 시작으로 해석하기 때문에 오류가 발생한다.

This will generate an XML error:
이는 XML 오류를 발생한다.


<message>if salary < 1000 then</message>

To avoid this error, replace the "<" character with an entity reference:
이 오류를 피하기 위해
개체 참조를 통해 "<" 문자를 대체하라.


<message>if salary < 1000 then</message>

There are 5 predefined entity references in XML:
XML에는 미리 정의된 5개의 개체 참조가 있다.



Note: only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it. 

주석 : 문자 "<" 와 "&"만 XML에서 엄격하게 불법이다. 부등호 크다를 뜻하는 문자는 합법이지만 이를 사용하는 것은 좋은 습관이다.


Comments in XML
XML의 주석

The syntax for writing comments in XML is similar to that of HTML.
XML에서 주석을 쓰는 구문은 HTML과 비슷하다.

<!-- This is a comment -->


White-space is Preserved in XML
XML에서 공백은 보존된다.

HTML truncates multiple white-space characters to one single white-space:
HTML은 여러 개의 공백 문자들을 하나의 공백으로 생략한다.


HTML: Hello           my name is Tove
Output: Hello my name is Tove.


With XML, the white-space in a document is not truncated.
XML에서 문서의 공백문자는 생략되지 않는다.


XML Stores New Line as LF
XML은 LF로써 개행문자를 저장한다.

In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). The character pair bears some resemblance to the typewriter actions of setting a new line. In Unix applications, a new line is normally stored as a LF character. Macintosh applications use only a CR character to store a new line.
윈도우 응용프로그램에서 개행문자는 보통 두 개의 문자 짝(CR과 LF)으로 저장된다. 이 짝은 새로운 줄을 설정하는 데 타자기의 행위와 비슷한 점을 가진다. UNIX 응용 프로그램에서 개행문자는 보통 하나의 LF 문자로 저장된다. 매킨토시 응용 프로그램에서는 개행문자를 저장하는 데 CR 문자만 사용한다.


Reference : http://www.w3schools.com/xml/xml_syntax.asp

'컴퓨터 공부 > 번역' 카테고리의 다른 글

6. XML 속성  (0) 2009.05.13
5. XML 엘레먼트  (0) 2009.05.13
3. XML 트리  (0) 2009.05.12
2. 어떻게 XML이 사용될 수 있을까?  (0) 2009.05.12
1. XML 소개  (0) 2009.05.12