xml: standard meta-markup languagevmlab.suwon.ac.kr/mwlee/data2/file/3_xml(20140917).pdf · xml...
TRANSCRIPT
XML: Standard Meta-Markup
Language
박창섭 동덕여대 컴퓨터학과
2014. 9. 17
Agenda
1. XML Overview – XML 개요 – History of XML – XML 사용 분야 – XML 관련 기술 – XML로 정의된 Markup 언어
2. XML 기본 문법
– 정형화된 XML 문서 – XML 문서구조 – XML Elements – XML Attributes – etc.
1. XML Overview
XML 개요 XML (eXtensible Markup Language)
− 문서를 사람과 기계가 이해할 수 있는 포맷으로 인코딩하기 위한 규칙을 정의하는 마크업 언어
A markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable
− 인터넷 상에서 데이터를 표현하고 공유하기 위한 산업계 표준 언어
A de facto standard language for data representation and interchange over the Internet
XML 개요 XML (eXtensible Markup Language)
– eXtensible: 새로운 markup을 정의할 수 있음
– Markup Language
문서의 내용(content)에 부가적인 정보(markup)를 추가할 수 있는 언어
e.g. HTML stylistic markup: e.g. <FONT>, <B>, <I>, <TABLE>
structural markup: e.g. <P>, <A>
semantic markup: e.g., <TITLE>, <BODY>
XML로 정의되는 markup은 HTML과 달리 문서의 구조와 의미를 정의하기 위해 사용됨
XML 개요 Markup Language
– markup을 사용하여 문서의 내용을 구조적으로 구분함으로써 내용을 쉽게 이해할 수 있도록 함
– markup 언어는 문서를 조직화하고 구조화시켜 문서의 내용을 정확하게 표현 및 전달할 수 있음
<warning> <para> This substance if hazardous to health </para> <para> 7 for information on protective clothing required.</para> <logo url=“image.gif”/> </warning>
Markups <transaction> <time date=“20110509”/> <amount>123</amount> <currency type=“pounds”/> <from id=“x98765”> J. Smith</from> <to id=“x56565>M. Jones</to> </transaction>
Contents
XML 개요 Generalized Markup
– XML markup은 문서의 display format(서식) 정보가 아닌, 문서의 구조와 의미를 나타냄
<dl> <dt>California love <dd>by Tupac <ul> <li>publisher : R record <li>length : 4:30 <li>date : 1999/10/10 </ul> </dl>
<song> <title>California love</title> <artist>Tupac</artist> <publisher>R record</publisher> <length>4:30</length> <date>1999/10/10</date> </song>
XML: 문서의 구조와 의미를 지정하기 위
해 사용자가 직접 태그를 정의해서 사용
HTML: 화면 출력 모양을 지정하기 위해
미리 정의된 태그를 이용
XML 개요 XML = Meta Markup Language
– 새로운 markup 언어를 정의할 수 있음
– e.g. XML Schema
<?xml version=“1.0”?> <memo priority=“important”> <to>John</to> <subject>CS1111</subject> <message> Don’t forget to attend the class <emphasis>on Friday</emphasis> Good luck to you. </message> <from>Tomas</from> </memo >
<schema targetNamespace=“http://www.example.com/Memo” xmlns:m =“http://www.example.com/Memo” xmlns="http://www.w3.org/2001/XMLSchema"> <element name=“memo“ type=“m:memoType"/> <complexType name=“memoType"> <sequence> <element name=“to" type=string/> <element name=“subject" type=string/> <element name=“message" type=“m:msgType"/> <element name=“from" type=" string"/> </sequence> <attribute name=“priority” type=“string”/> </complexType> . . . . . . </schema>
XML 개요 XML vs. {SGML, HTML, XHTML}
– SGML(Standard Generated Markup Language) 새로운 마크업 언어를 정의하기 위한 대표적인 Meta Markup
Language 1986년 ISO에서 국제표준으로 채택됨 문법이 복잡하고 응용 S/W를 구현하기 어려워 공공기관 및 출판업계에서 제한적으로 사용됨
– XML SGML의 부분집합으로, SGML의 장점을 취하고 복잡성을 배제하여 개발된 Meta Markup Language
1996년 W3C에서 개발 (http://www.w3.org/XML ) – HTML
SGML로 정의된 웹 문서 작성용 마크업 언어 – XHTML
XML로 정의된 웹 문서 작성용 마크업 언어
XML vs. {SGML, HTML, XHTML}
XML 개요
XHTML
XHTML 문서
XML 개요 XML의 장점
– 호환성(Portability)
– 독립성(Independence from HW, OS, and PL)
– 다양한 포맷으로 변환 가능(One data source, multiple views)
– 검색능력의 향상(Improved data searches)
– 편리한 기반 기술
– 풍부한 XML 지원 소프트웨어
History of XML ISO, 1986
– SGML & SGML DTD
W3C – XML 1.0 & XML DTD (Recommendation), 1998/02
– XML 1.0 & XML DTD (Second Edition), 2000
– XML 1.0 (Third Edition), 2004/02
– XML 1.0 (Fourth Edition), 2006/08
– XML 1.0 (Fifth Edition), 2008/11
– XML 1.1 (Recommendation), 2004/02
– XML 1.1 (Second Edition), 2006/08
– XML Schema (Second Edition), 2004/10
– Namespaces in XML 1.1 (Second Edition), 2006/08
History of XML XML 1.0 (Fifth Edition) Recommendation
– http://www.w3.org/TR/2008/REC-xml-20081126/
XML 사용 분야 인터넷 상에서 데이터 표현 및 교환을 위한 산업계 표준(de facto
standard) 언어/문서 양식으로 사용됨 – Electronic Data Interchange (EDI)
시스템 간 데이터 교환을 위한 공통 포맷으로 사용 – Business to Business Integration
기업간 비즈니스 애플리케이션의 통합 (EAI) XML Web Services
– Advanced Information Management System 모든 유형의 데이터 통합 관리 Co-Work 지식관리시스템
– Document Publishing Applications – Advanced Search System
구조 검색, 상품 카탈로그 검색
XML 사용 분야 Electronic Data Interchange
– 이기종 시스템 간의 정보 공유를 위한 데이터 교환 프로토콜로 XML 이용
XML 사용 분야 Business to Business Integration
– Web Services 기술을 이용한 분산 애플리케이션의 연동 및 통합 Simple Object Access Protocol(SOAP)을 이용한 원격 객체 호출
XML is a family of technologies – Schema: DTD, XML Schema
– Rendering: XSL, CSS
– Transformation: XPath, XSLT, XSL-FO
– Query: XPath, XQuery
– Publishing: XSL-FO
– Processing: XProc (XML Pipelining)
– Security: XML Encryption, XML Signature, XKMS
– Components: XLink, XPointer, XInclude, XForms, etc.
– Internationalization: ITS
– Parsing API: DOM, SAX
http://www.w3.org/standards/xml/
XML 관련 기술
DTD & XML Schema – XML 문서 구조 정의
<students> <student sno=‘s100’> <name>홍길동</name> <age>23</age> <phone>02-123-8989</phone> <address>서울시 성북구 월곡동</address> </student> … </students>
student.xml <!ELEMENT students (student*)> <!ELEMENT student (name,age,phone,address)> <!ATTLIST student sno ID #REQUIRED> <!ELEMENT name (#PCDATA)> <!ELEMENT age (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT address (#PCDATA)>
student.dtd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="students"> <xsd:sequence> <xsd:element name="student" type="studentType" maxOccurs="unlimited"> </xsd:sequence> </xsd:element> <xsd:complexType name="studentType"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/><xsd:element name="age" type="xsd:string"/> <xsd:element name="phone" type="xsd:string"/><xsd:element name="address" type="xsd:string"/> </xsd:sequence> <xsd:attribute name="sno" type="xsd:id"/> </xsd:complexType> </xsd:schema>
student.xsd
XPath – XML 문서의 엘리먼트나 속성을 접근하기 위한 경로(path) 표현
/booklist/book/title //book[contains(title, ‘XML’)]/price
XML 문서
<?xml vesion=”1.0” encoding=”euc-kr”?> <booklist> <book id=”b1”> <title>Java and XML</title> <author>Chris Park</author> <price>25000</price> </book> <book id=”b2”> <title>전자상거래</title> <author>홍길동</author> <author>박문수</author> <price>30000</price> </book> … </booklist>
eXtensible Stylesheet Language - Transformation(XSLT)
– XML 문서의 변환 및 출력 양식 지정
<xsl:stylesheet version="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:template match="/"> <html><body> <h2><font color="blue">Our Book's List</font></h2> <table> … <xsl:apply-templates select="/booklist/book"/> </table> </body></html> </xsl:template> <xsl:template match="book" priority="1" > <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="author"/></td> </tr> </xsl:template> …
Document Object Model(DOM) – XML 문서를 parsing 및 조작하기 위한 tree-based API
Simple API for XML(SAX) – XML 문서를 parsing 및 조작하기 위한 event-based API
XML로 정의된 Markup 언어 Non-textual Data
Language Purpose Document, Phase (R,
SMIL
Multimedia documents
- Synchronized Multimedia Integration Language (SMIL 3.0), R, Dec. 2008
MathML
Mathematical notation
- A MathML for CSS profile, R, June 2011 - Mathematical Markup Language (MathML) Version 3.0, R, Oct. 2010
SVG X3D
Vector graphics Extensible 3D Graphics
- Scalable Vector Graphics (SVG) 1.1 (2nd Edition), R, Aug. 2011 - ISO/IEC 19775-1.2:2008: X3D Architecture and base components Edition 2
VoiceXML CCXML SSML
Voice markup and telephony call control; to enable access to the Web using spoken interaction
- Voice Extensible Markup Language (VoiceXML) 2.1, R, June 2007 - Voice Browser Call Control: CCXML Version 1.0, R, July 2011 - Speech Synthesis Markup Language (SSML) Version 1.1, R, Sept. 2010
EmotionML
To describe human emotions
- Emotion Markup Language (EmotionML) 1.0, CR, May 2012
XML로 정의된 Markup 언어 Web Publishing
Language Purpose Document, Phase (R,
XHTML
Reformulation of HTML 4.0 in XML
- XHTML™ 1.0: The Extensible HyperText Markup Language (Second Edition), A Reformulation of HTML 4 in XML 1.0, R, Jan. 2000, revised 1 August 2002
XML Events
To represent asynchronous occurrences, such as mouse clicks, in XHTML or in other XML markup
- XML Events, An Events Syntax for XML, R, Oct. 2003
XForms Web forms - XForms 1.0 (Third Edition), R, Oct. 2007
XHTML-Print
Simple XHTML suitable for printing from mobile devices as well as for display
- XHTML-Print - Second Edition, R, Nov. 2010
Polyglot Markup
For writing documents that serve bothas HTML 5 and XML documents
- Polyglot Markup: HTML-Compatible XHTML Documents , TR, March 2012
XML로 정의된 Markup 언어 Metadata and Semantic Web
Language Purpose Document, Phase (R,
RDF
Metadata for Web resources
- Resource Description Framework (RDF): Concepts and Abstract Syntax, R, Feb. 2004 - RDFa Core 1.1, R, June 2012
RDF Schema
To describe RDF vocabularies
- RDF Vocabulary Description Language 1.0: RDF Schema, R, Feb. 2004
OWL
Semantic markup language for publishing and sharing ontologies on the Web
- OWL 2 Web Ontology Language. Primer, R, Oct. 2009
SPARQL
Query language for RDF
- SPARQL Query Language for RDF, R, Jan. 2008
RIF Rule Exchange Format - RIF Core Dialect, R, June 2010
XML로 정의된 Markup 언어 Web Communication and Services
Language Purpose Document, Phase (R,
XML-Signature Associating digital objects by digital signatures in XML format
- XML-Signature Syntax and Processing (Second Edition), R, June 2008
XML Encryption
Encrypting data and representing the result in XML
- XML Encryption Syntax and Processing, R, Dec. 2002 - Decryption Transform for XML Signature, R, Dec. 2002
XKMS
Protocol for distributing and registering public keys
- XML Key Management Specification (XKMS) Version 2.0, R, June 2005
SOAP
Protocol
- SOAP Version 1.2 Part 0: Primer (Second Edition), R, April 2007
WSDL
To describe Web services
- Web Services Description Language (WSDL) Version 2.0 Part 0: Primer, R, June 2007
SML Service modeling
- Service Modeling Language, Version 1.1, R, May 2009
XML로 정의된 Markup 언어 Word processing formats
– Open Document Format: http://www.odfalliance.org/ – Open Office XML: http://www.openxmlcommunity.org/
Graphics formats – Scalable Vector Graphics(SVG): http://www.w3.org/Graphics/SVG/ – Extensible 3D Graphics (X3D): http://www.web3d.org/
예: http://www.web3d.org/x3d/content/examples/HelloWorld.x3d, http://www.web3d.org/x3d/content/examples/X3dResources.html#Examples
Web feed formats – RSS: http://en.wikipedia.org/wiki/RSS
예: http://www.hani.co.kr/rss/, http://news.google.co.kr/, http://section.blog.naver.com/
Messaging – XML-RPC, SOAP, REST
Programming – Deployment Descriptors in JavaEE(JSP, EJB)/Struts/Spring applications – UI Layout definition in Android applications
XML Data Repository at UW Database Group – http://www.cs.washington.edu/research/xmldatasets/
XML로 정의된 Markup 언어 (예) OFX(Open Financial eXchange)
– Request of an open-ended statement download (no start/end dates) for savings account # 098-121 <OFX>
<SIGNONMSGSRQV1> … </SIGNONMSGSRQV1> <BANKMSGSRQV1> <STMTTRNRQ> <TRNUID>23382938 <STMTRQ> <BANKACCTFROM> <BANKID>987654321 <ACCTID>098-121 <ACCTTYPE>SAVINGS </BANKACCTFROM> <INCTRAN> <INCLUDE>Y </INCTRAN> </STMTRQ> </STMTTRNRQ> </BANKMSGSRQV1> </OFX>
XML로 정의된 Markup 언어 (예) MathML
<math xmlns="http://www.w3.org/1998/Math/MathML"> <apply><in/> <ci>x</ci> <set> <apply><divide/> <apply><plus/> <apply><minus/> <ci>b</ci> </apply> <apply><root/> <apply><minus/> <apply><power/> <ci>b</ci> <cn>2</cn> </apply> <apply><times/> <cn>4</cn> <ci>a</ci> <ci>c</ci> </apply> </apply> </apply> </apply> <apply><times/> <cn>2</cn> <ci>a</ci> </apply> </apply> ... </set> </apply> </math>
XML로 정의된 Markup 언어 (예) RSS(Rich Site Summary / Really Simple Syndication)
– Web feed formats used to publish frequently updated works - such as blog entries, news headlines, etc. - in a standardized format
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>전체기사 : 뉴스 : 한겨레 뉴스 - 인터넷한겨레</title> <link>http://www.hani.co.kr/arti/</link> <description>인터넷한겨레 - 토론이 살아 있는 생생한 뉴스</description> <dc:language>ko</dc:language> <copyright>Copyright The Hankyoreh.</copyright> <lastBuildDate>Mon, 05 Mar 2012 23:32:40 +0900</lastBuildDate> <item> <title>‘광주 불법 조직선거’ 구의원</title> <link>http://www.hani.co.kr/arti/society/522135.html</link> <description><![CDATA[ 광주 동구의 민주통합당 불법 선거인단 모집사건의 핵심인 구의원과 통장 등 4명이 추가로 검찰에 구속됐다. 광주지법 장철익 영장전담판사는 5일 민주통합당 국민경선을 앞두고 ..]]></description> <pubDate>Mon, 05 Mar 2012 22:37:38 +0900</pubDate> <author>안관옥 기자</author> <dc:category>사회</dc:category> </item> <item> … </item> <item> … </item> … </channel> </rss>
XML로 정의된 Markup 언어 (예) X3D(Extensible 3D Graphics)
– ISO standard XML-based file format for representing 3D computer graphics
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "http://www.web3d.org/specifications/x3d-3.1.dtd"> <X3D profile='CADInterchange' version='3.1' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' http://www.web3d.org/specifications/x3d-3.1.xsd '> <head> <component level='2' name='CADGeometry'/> <meta name='title' content='CadTeapot.x3d'/> <meta name='description' content='Teapot model demonstrating proper hierarchy of CAD nodes: CADLayer, CADAssembly, CADPart, and then CADFace.'/> <meta name='creator' content='Alan Hudson, Don Brutzman'/> … </head> <Scene> <Background skyColor='0.9607843 1 0.9607843'/> <Viewpoint description='Hello CAD teapot' position='0 0 35'/> <CADLayer DEF='TopLayer' name='Single topmost CADLayer for this model'> <CADAssembly name='Assembled Teapot'> <CADPart name='Body'> <CADFace name='Teapot body IFS mesh'> <Shape containerField='shape'> <Appearance DEF='APP01'><Material diffuseColor='0.3451 0.5608 0.8824'/></Appearance> <IndexedFaceSet creaseAngle='1.0' coordIndex='0 5 6 0 5 6 -1 6 1 0 -1 1 6 7 -1 7 2 1 -1 2 7 8 -1 8 3 2 -1 3 8 9 -1 9 4 3 -1 5 10 11 -1 11 6 5 -1 6 11 12 -1 12 7 6 -1 7 12 13 -1 13 8 7 -1 8 13 14 -1 14 9 8 -1 10 15 16 -1 16 11 10 -1 11 16 17 -1 17 12 11 -1 12 17 18 -1 18 13 12 -1 13 18 … '/>
2. XML 기본 문법
정형화된 XML 문서 정형화된 XML 문서(Well-Formed XML Documents)
– XML 권고안에 정의된 기본 규칙을 잘 지켜서 작성된 문서
XML Document Production Rules
하나의 루트 엘리먼트(root element) 존재
각 엘리먼트는 시작 태그(start tag)와 종료 태그(end tag)를 가짐 • <element-A> … </element-A>
엘리먼트들은 서로 올바르게 중첩되어야 함(nested properly) • <element-A> … <element-B> … </element-B> … </element-A>
참고: 유효한 XML 문서(Valid XML Documents) – 정형화된 문서이면서, XML로 정의된 특정 마크업 언어에 의해 작성된 문서 DTD나 XML Schema를 통해 정의된 마크업 언어의 문법을 따르는 문서
XML 문서 구조 XML Document Production Rules
– [1]: XML 문서의 구조는 서두(prolog)와 (루트) 엘리먼트, 그리고 기타(Misc) 부분으로 구성됨
– [22]: 서두는 XML 선언(XMLDecl), 문서 유형 선언(doctypedecl), 기타 부분으로 구성됨
– [27]: 기타 부분은 주석(Comment), PI(Processing Instruction), 공백(S)으로 구성됨
– [39][43]: 엘리먼트는 컨텐트(content)를 가질 수 있음, 컨텐트는 문자데이터(CharData), 자식 엘리먼트, 참조(Reference), CDATA Section, PI, 주석 등을 포함할 수 있음
[1] document ::= prolog element Misc* [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' [27] Misc ::= Comment | PI | S [39] element ::= EmptyElemTag | STag content ETag [WFC: Element Type Match] [VC: Element Valid] [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* … WFC: Well-Formedness Constraint, VC: Validity Constraint
XML 문서 구조 XML 문서
<?xml version=”1.0” encoding=”euc-kr”?> <!-- XML 선언 --> <!-- 문서 유형 선언 --> <!DOCTYPE booklist SYSTEM “bml.dtd”> <!-- 문서의 구조를 xhtml 문서로 변경 (PI) --> <?xml-stylesheet type=”text/xsl” href=”bml.xsl”?> <booklist> <book id="b1" kind="k2"> <title>XML 개론</title> <author>홍길동</author> <publisher>가나출판사</publisher> </book> <book id="b2" kind="k1"> <title>Java and XML</title> <author>Chris Park</author> <publisher>ABC Pub.</publisher> </book> </booklist>
Prolog
Element
XML Declaration XML 선언(declaration)
– 현재 작성중인 문서가 XML 문서임을 명시적으로 표현하는 것
– version 속성: XML version info
– encoding 속성: XML 문서가 어떤 인코딩 방식을 사용하는지를 지정
(default: UTF-8)
– standalone 속성: 외부에 정의된 DTD 문서의 참조 필요 여부를 표시
<?xml version="버전번호" encoding=“인코딩방식" standalone="yes/no"?>
XML Elements 기본 규칙
– 모든 XML 문서는 단 하나의 루트 엘리먼트(root element)를 갖음
– 엘리먼트는 시작 태그와 종료 태그 한 쌍으로 구성되며 태그명은 동일해야 함
– 시작태그와 종료 태그 사이에는 엘리먼트의 내용(content)으로 문자 데이터나 자식 엘리먼트 등이 올 수 있음
– 엘리먼트는 부가적인 정보를 나타내는 속성(attribute)을 가질 수 있음
– 엘리먼트 이름은 반드시 XML 이름 작성 규칙을 따라야 함
XML Elements
XML 이름 작성 규칙 1 이름은 문자(한글도 포함)나 “_”로 시작할 수 있으나 숫자나 ‘.’ 등으로 시작할 수 없다. 2 두 번째 문자부터는 숫자 및 “_”, “-“, ”.” 등도 가능하다. 3 태그 이름은 공백문자를 포함할 수 없다. 4 ‘:’ 문자는 쓸 수는 있지만 네임스페이스와 관련된 기호이므로 사용하지 않는 것이 좋다 5 태그 이름은 대소문자를 구별한다. 6 태그 이름은 ‘xml’이나 ‘XML’로 시작할 수 없다.
<7Book> 첫 글자는 숫자를 사용할 수 없다.
<c++> ‘_’, ‘-‘, ‘.’, ‘:’ 이외의 특수 문자는 사용할 수 없다.
<book list> 태그 이름에 공백을 사용할 수 없다.
< book> ‘<’ 다음에 공백을 두어서는 안 된다.
<xml-book> 태그 이름이 xml로 시작하면 안 된다.
< 올바른 태그 이름 >
<book> <_book> <책> <book1> <book-1> <Book>
< 잘못된 태그 이름 >
XML Elements
<element-name> element’s content </element-name>
시작 태그 종료 태그
<PLAY name=“Hamlet” year=‘2000’> <ACT> <SCENE id=“000”> <TITLE> Intro </TITLE> </SCENE> </ACT> <POSTER image=“hamlet.gif”/> </PLAY>
시작 태그
종료 태그
내용(content)
XML Elements 엘리먼트의 종류 (1) 내용(content)을 갖는 엘리먼트
- 문자 데이터나 자식 엘리먼트를 갖는 엘리먼트
(2) 내용이 없는 빈 엘리먼트 (empty element)
- 문자 데이터나 자식 엘리먼트를 갖지 않는 엘리먼트
<image src=”D:\temp\image1.gif”/> <image src=”D:\temp\image1.gif”></image> 와 동일
<book> <title>Java and XML</title> </book>
XML Elements 엘리먼트의 내용(content)
<book kind=”computer”> </book>
▶ 자식 엘리먼트(Child Element) ▶ 문자 데이터(Character Data) ▶ 엔티티 또는 문자 참조(Reference) ▶ CDATA 섹션(Character Data Section) ▶ 프로세싱 지시자(Processiong Instruction) ▶ 주석(Comment) ▶ 공백 문자열(White Space)
<시작태그 속성명=”속성값”>
내용 (문자 데이터 or 자식 엘리먼트)
</종료태그>
XML Elements 자식 엘리먼트
– 엘리먼트의 내용에 자식 엘리먼트(child element)를 포함할 수 있음
XML 문서
<?xml version="1.0" encoding="euc-kr" standalone="yes"?> <booklist> <book> <title>Java and XML</title> <publisher>ABC Pub.</publisher> </book> </booklist>
자식 엘리먼트
부모 엘리먼트
Character Data
■ XML 선언 <?xml version=”1.0” encoding=”euc-kr”?>
■ 문서 유형 선언 <!DOCTYPE booklist SYSTEM “bml.dtd”>
■ 프로세싱 지시자(PI) <?xml-stylesheet type=”text/x니” href=”bml.xsl”?>
■ 주석 <!-- 주석 내용 -->
■ 시작태그 및 끝태그 <book> </book>
■ 빈 엘리먼트 태그 <imgae src=”image1.gif”/>
■ 엔티티 참조 DTD에 정의되어 있는 엔티티 참조 (예) &pub1;
■ 문자 참조 
진수; 진수;
■ CDATA 섹션 구분자 <![CDATA[ 문자 데이터 ]]>
■ 최상위 공백 문자열 루트 엘리먼트 외부에 있는 공백 문자열
■ Text 선언 <?xml version=”1.0” encoding=”euc-kr”?>
문자 데이터(Character Data)란 XML parser가 해석할 수 있는 내용 중 마크업(mark-up)을 제외한 부분을 말함
<XML 마크업(mark-up) >
Entity Reference 문자 데이터 내에는 ‘&’ 문자와 ‘<’ 문자를 사용할 수 없음
– ‘&’ 문자는 엔티티(entity) 참조의 시작을 의미
– ‘<’ 문자는 엘리먼트의 태그, 또는 CDATA 섹션의 시작을 의미
XML 문서에서 특수문자를 사용하기 위해서는 개체 참조(Entity Reference)나 문자 참조(Character Reference) 사용 – Built-in entities
표현 문자 문자 코드 개체 참조명 어 원
< < < less then
> > > greater then
‘ ' ' apostrophe
“ " " quotation marks
& & & ampersand
CDATA Section
대부분의 문자 데이터인 PCDATA(Parsed Character DATA)는 XML 파서가 해석(parsing)하는 데이터를 말함
CDATA 섹션(Section) 내에 정의된 문자 데이터는 XML 파서가 해석하지 않고 바로 응용 프로그램(application)에게 전달
특수기호가 많은 경우 CDATA 섹션을 사용하면 편리
<?xml version="1.0" encoding="euc-kr"?> <Root> if (a > 0 && a < 3) error 발생! </Root>
<?xml version="1.0" encoding="euc-kr"?> <Root> if (a > 0 && a < 3) </Root>
<?xml version="1.0" encoding="euc-kr"?> <Root> <![CDATA[ if (a > 0 && a < 3) ]]> </Root>
XML Attributes 속성(attributes)
– 엘리먼트에 대한 부가적인 정보나 데이터를 표현하기 위한 방법
– 하나의 엘리먼트가 여러 개의 속성들을 가질 수 있음
– 형식: 시작 태그의 일부로 표현
– 구성요소: 속성명=“속성값” 으로 표현
<element_name attribute1="attribute_value1" attribute2="attribute_value2"... >
<student sid="100">
엘리먼트명 속성명 속성값
XML Attributes 주의 사항
– 속성은 반드시 속성 값을 가져야 함
빈 문자열을 포함할 수도 있음 (“”)
– 속성값은 큰 따옴표(“)나 작은 따옴표(‘)를 사용해야 함
– 속성명 부여 방법은 엘리먼트의 태그명 부여 방법과 동일
대소문자를 구별
‘xml'이라는 문자열로 시작할 수 없음
숫자로 속성명을 시작할 수 없음
– 한 엘리먼트에 같은 이름의 속성을 두 개 이상 선언할 수 없음
XML Attributes Elements vs. Attributes
<student sid=“100”> <name>홍길동</name> <age>30</age> <address>서울시 성북구 월곡동</address> <phone type = “home”>02-123-2345</phone> <phone type = “office”>031-777-9999</phone> </student>
<student sid=“100” name=“홍길동 age=“30” address=“서울시 성북구 월곡동 ” phone=“02-123-2345” phone=“031-777-9999”> error! </student>
<student sid=“100”> <name> 홍길동 </name> <age>30</age> <address> 서울시 성북구 월곡동 </address> <phone> <home>02-123-2345</home> <office>031-777-9999</office> <mobile>010-222-3333</mobile> </phone> </student>
<student sid=“100” name=“홍길동 age=“30” address=“서울시 성북구 월곡동 ” h_phone=“02-123-2345” o_phone=“031-7777-9999” m_phone=“010-222-3333”> </student>
Processing Instruction 처리 명령어(Processing Instruction; PI)
– 해당 XML 문서를 처리하는 응용 프로그램(application)에게 XML 문서의 처리 방법을 지시함
– 형식
name_processor: 명령문이 전달되는 응용 프로그램 식별자 ‘<?’와 ‘name_processor’ 사이에 공백문자를 포함할 수 없음
instruction: 응용 프로그램이 어떻게 문서를 처리할지를 나타냄
– 예: CSS, XSL
<?name_processor instruction ?>
<?xml-stylesheet type=“text/css” href=“student_style.css” ?>
Comments
주석(comment)은 XML 문서를 작성하는 사람과 이용하는 사람이 좀더 쉽게 문서의 내용을 이해할 수 있도록 덧붙인 설명
XML 문서
<?xml version="1.0" encoding="euc-kr" standalone="yes"?> <!-- 루트 엘리먼트 --> <booklist> <!-- <book> <title>XML 기초서</title> <publisher>&pub1;</publisher> </book> --> <book> <title> <!-- 알기 쉬운 --> XML 기초서</title> <publisher>&pub1;</publisher> </book> </booklist>
<!-- 주석 내용 -->
References Extensible Markup Language (XML) 1.0 (Fifth Edition)
W3C Recommendation, 26 November 2008 – http://www.w3.org/TR/REC-xml/
W3C XML Technology – http://www.w3.org/standards/xml/
XML Tutorial – http://www.w3schools.com/xml/
Books – 신민철, Java 개발자를 위한 XML, 프리렉, 2006
– B. D. McLaughlin & J. Edelson, Java and XML, 3rd Ed., O'Reilly, 2006
– 손진현, 김명호, XML 개념 및 응용, 홍릉과학출판사, 2008