XmlListModelRole QML Type
XmlListModel...에 역할을 지정하려면 자세히...
Import Statement: | import QtQml.XmlListModel |
속성
- attributeName : string
- elementName : string
- name : string
자세한 설명
참조 Qt Qml.
속성 문서
attributeName : string |
데이터를 읽는 데 사용되는 XML 요소의 속성입니다. XML 요소는 elementName 속성으로 지정됩니다.
예를 들어 다음 모델에는 "title"이라는 역할이 있으며, 이 역할은 XML 요소 <title>
에서 데이터를 읽습니다. 또한 동일한 XML 요소 <title>
를 사용하지만 "created" 속성을 읽어 실제 값을 추출하는 "timestamp"라는 이름의 또 다른 역할이 있습니다.
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 } }
속성 이름이 지정되면 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>
에서 데이터를 읽습니다. 또한 동일한 XML 요소 <title>
를 사용하지만 "created" 속성을 읽어 실제 값을 추출하는 "timestamp"라는 이름의 또 다른 역할이 있습니다.
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 } }
© 2025 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.