Free Lines Arrow
본문 바로가기
Development/Qt

[Qt] QXml Parser 만들기 1 (xsd xml 만들기)

by skahn1215 2020. 5. 31.
728x90
반응형

XSD 와 XML 파일 만들기

QXml Parser 코드를 작성하기전 xsd 와 xml을 만드는 방법

 

XSD 란 XML 스키마 정의(XML Schema Definition) 입니다.

즉 xsd 를 통해 xml 이 정확하게 서식에 맞게 기술 되어 있는지 확인할수가 있습니다.

 

1. XML 만들기

일단 xml 을 정의 해줍니다.

저 같은 경우는

books 안에 book 이 있고 book의 속성들은 title, author, genre가진다고 정의 했습니다.

books 가 있고 그안에 폭풍의 언덕과 그리고 아무도 없었다 라는 책이있다고 가정을 하였습니다.

 

<books>

    <book>

        <title>WutheringHeights</title>

        <author>EmilyJaneBronte</author>

        <genre>Literaturefiction</genre>

    </book>

    <book>

        <title>AndThenThereWereNone</title>

        <author>AgathaChristie</author>

        <genre>Mystery</genre>

    </book>

</books>

 

2. XML 을 XSD로 변환 이 사이트에서 변환을 해줍니다.

https://www.liquid-technologies.com/online-xml-to-xsd-converter

 

Free Online XML to XSD Converter

 

www.liquid-technologies.com

그럼 아래와 같이 만들어 집니다.

3. XSD 분석 사용된 것만 분석하고 넘어 가겠습니다. 인터넷에 찾아보면 아주 잘 나와있습니다.

 

<?xml version="1.0" encoding="utf-8"?>

    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="books"

        <xs:complexType> 1. complexType        

            <xs:sequence>  2. sequence 지시자        

                <xs:element maxOccurs="unbounded" name="book">  3. 출현 빈도 지시자

                    <xs:complexType>

                        <xs:sequence>

                            <xs:element name="title" type="xs:string" />

                            <xs:element name="author" type="xs:string" />

                            <xs:element name="genre" type="xs:string" />

                       </xs:sequence>

                   </xs:complexType>

               </xs:element>

           </xs:sequence>

        </xs:complexType>

    </xs:element>

</xs:schema>

 

1. complexType

복합자는 내가 자식을 가지고 있다는 것을 알려줍니다.

즉 books 에 complexType 이 있다면 자식요소가 있다는 것입니다.

books 는 book 이라는 자식요소를 가지고 있죠

 

2.sequence 지시자

반드시 아래와 같은 순서대로 입력이 되어야 한다는 것을 말해줍니다.

즉 title, author, genre 순으로 와야 합니다.

 

3. 출현 빈도 지시자

<xs:element maxOccurs="unbounded" name="book">

maxOccurs 이 출현빈도 지시자 인데 만약 출현빈도 지시자가 없다면

<xs:element name="book"> 이렇게 되면 book 은 한번만 올수가 있습니다.

최대 수를 지정 할수 있습니다. 하지만 만약 books 안에 book이 없는 경우는?

 

<xs:element minOccurs="0" maxOccurs="unbounded" name="book">

위와 같이 작성한다면 book 은 아예 없거나 제한 없이 있을수 있다는 말이 됩니다.

 

 

728x90
반응형

'Development > Qt' 카테고리의 다른 글

[Qt] QImage를 text로 저장하기  (0) 2020.06.10
[Qt] QXml Parser 만들기 2 (code 작성)  (0) 2020.05.31

댓글