이 페이지에서

XmlListModelRole QML Type

XmlListModel 에 역할을 지정하기 위해. 더 보기...

Import Statement: import QtQml.XmlListModel

속성

상세 설명

참조 Qt Qml.

속성 문서

attributeName : string

데이터를 읽는 데 사용될 XML 요소의 속성입니다. XML 요소는 ` elementName ` 속성으로 지정됩니다.

예를 들어, 다음 모델에는 "title"이라는 역할이 있는데, 이 역할은 XML 요소 <title> 에서 데이터를 읽습니다. 또한 "timestamp"라는 또 다른 역할이 있는데, 이 역할은 동일한 XML 요소 <title> 를 사용하지만, "created" 속성을 읽어 실제 값을 추출합니다.

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    XmlListModelRole { name: "title"; elementName: "title" }
    XmlListModelRole {
        name: "timestamp"
        elementName: "title"
        attributeName: "created"
    }
}

ListView {
    anchors.fill: parent
    model: xmlModel
    delegate: Text { text: title + " created on " + timestamp }
}

attributeName이 지정된 경우, elementName 은 비워 둘 수 있습니다. 이 경우 쿼리의 최상위 XML 요소의 속성이 읽힙니다.

예를 들어, 다음과 같은 XML 문서가 있다고 가정해 보겠습니다.

<documents>
    <document title="Title1"/>
    <document title="Title2"/>
</documents>

문서의 제목을 추출하려면 다음 모델이 필요합니다:

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    XmlListModelRole {
        name: "title"
        elementName: ""
        attributeName: "title"
    }
}

지정된 XML 요소의 속성을 파싱할 필요가 없다면, 이 속성을 비워두기만 하면 됩니다.

elementName도 참조하십시오 .

elementName : string

데이터를 읽는 데 사용될 XML 요소의 이름 또는 해당 XML 요소에 대한 경로입니다. 해당 요소에는 반드시 텍스트가 포함되어 있어야 합니다.

선택적으로 attributeName 속성을 지정하여 데이터를 추출할 수 있습니다.

예를 들어, 다음 모델에는 "title"이라는 역할이 있으며, 이 역할은 XML 요소 <title> 에서 데이터를 읽습니다. 또한 "timestamp"라는 또 다른 역할이 있는데, 이 역할은 동일한 XML 요소 <title> 를 사용하지만, "created" 속성을 읽어 실제 값을 추출합니다.

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    XmlListModelRole { name: "title"; elementName: "title" }
    XmlListModelRole {
        name: "timestamp"
        elementName: "title"
        attributeName: "created"
    }
}

ListView {
    anchors.fill: parent
    model: xmlModel
    delegate: Text { text: title + " created on " + timestamp }
}

attributeName 이 지정된 경우, elementName은 비워둘 수 있습니다. 이 경우 쿼리의 최상위 XML 요소의 속성이 읽힙니다.

예를 들어, 다음과 같은 XML 문서가 있다고 가정해 보겠습니다.

<documents>
    <document title="Title1"/>
    <document title="Title2"/>
</documents>

문서의 제목을 추출하려면 다음 모델이 필요합니다:

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    XmlListModelRole {
        name: "title"
        elementName: ""
        attributeName: "title"
    }
}

elementName 속성에는 실제로 중첩된 XML 요소로의 경로를 포함할 수 있습니다. 경로에 포함된 모든 요소는 '/' 문자로 연결되어야 합니다.

예를 들어, 다음과 같은 XML 문서가 있다고 가정해 봅시다:

<documents>
    <document>
        <title>Title1</title>
        <info>
            <num_pages>10</num_pages>
        </info>
    </document>
    <document>
        <title>Title2</title>
        <info>
            <num_pages>20</num_pages>
        </info>
    </document>
</documents>

다음과 같은 역할을 사용하여 페이지 수를 추출할 수 있습니다:

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    // ...
    XmlListModelRole {
        name: "pages"
        elementName: "info/num_pages"
    }
}

참고: 요소경로는 '/' 로 시작하거나 끝날 수 없습니다.

attributeName항목도 참조하십시오 .

name : string

역할의 이름입니다. 이 이름은 해당 역할의 모델 데이터에 접근할 때 사용됩니다.

예를 들어, 다음 모델에는 "title"이라는 이름의 역할이 있으며, 뷰의 델리게이트를 통해 이 역할에 접근할 수 있습니다:

XmlListModel {
    id: xmlModel
    source: "file.xml"
    query: "/documents/document"
    XmlListModelRole { name: "title"; elementName: "title" }
}
ListView {
    model: xmlModel
    delegate: Text { text: title }
}

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.