CS/CS 전공 지식 노트

[CS] XML에 대해 알아보자

jordancancode 2024. 7. 25. 15:42

개념

Extensible Markup Language, 마크업 형태를 쓰는 데이터 교환 형식

마크업 형태

마크업은 태그 등을 이용하여 문서나 데이터의 구조를 나타내는 방법

  • 속성 부여도 가능

구성

  1. 프롤로그 : 버전, 인코딩
  2. 루트 요소 : 단 하나만 있음!
  3. 하위 요소들
<?xml version="1.0" encoding="utf-8"?>		<-- 프롤로그

<layout xmlns:android="http://schemas.android.com/apk/res/android"		<-- 루트 요소
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".SplashActivity">		<-- 하위 요소
        
        <TextView
            android:id="@+id/textView"
            android:layout_width="116dp"
            android:layout_height="62dp"
            android:gravity="center"
            android:text="Splash"
            android:textColor="#000000"
            android:textSize="28sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:ignore="MissingConstraints" />		<-- 하위요소
            
    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

HTML과 XML의 차이

HTML XML
데이터의 표시 데이터 저장 및 전송
미리 정의된 태그 고유한 태그 만들고 정의
대.소문자 구분 X 대/소문자 구분
상대적으로 가볍다 약간 무겁다 (닫힘 태그 필요)

JSON과 XML의 차이

JSON XML
상대적으로 가볍다 약간 무겁다 (닫힘 태그 필요)

 

활용

sitemap.xml으로 쓰임

  • sitemap.xml : 서비스 내의 모든 페이지들을 리스트업한 데이터. 크롤러가 모든 페이지들을 크롤링할 수 있게끔 해준다.

여러 언어에서도 독립적으로 사용

반응형