我正在尝试将xml数据导入到QML XmlListModel中,我现在已经完成了大部分工作,但最后一部分丢失了多个类别流。
xml本身如下所示:
<root>
<fullscreen>false</fullscreen>
<aspectratio>default</aspectratio>
<audiodelay>0</audiodelay>
<apiversion>3</apiversion>
<currentplid>4</currentplid>
<time>1</time>
<volume>0</volume>
<length>9907</length>
<random>false</random>
<rate>1</rate>
<state>paused</state>
<loop>false</loop>
<version>2.1.5 Rincewind</version>
<position>0.00018763827392831</position>
<repeat>false</repeat>
<subtitledelay>0</subtitledelay>
<category name="meta">
<info name="title">
The Movie
</info>
<info name="filename">
The Movie
</info>
</category>
<category name="Stream 0">
<info name="Type">Video</info>
<info name="Frame rate">23.976215</info>
<info name="Decoded format">Planar 4:2:0 YUV</info>
<info name="Codec">H264 - MPEG-4 AVC (part 10) (avc1)</info>
<info name="Language">English</info>
<info name="Resolution">1024x542</info>
</category>
<category name="Stream 1">
<info name="Bitrate">384 kb/s</info>
<info name="Type">Audio</info>
<info name="Channels">3F2R/LFE</info>
<info name="Sample rate">48000 Hz</info>
<info name="Language">Russian</info>
<info name="Codec">A52 Audio (aka AC3) (a52 )</info>
</category><category name="Stream 6"><info name="Description">Full</info>
<info name="Type">Subtitle</info>
<info name="Language">English</info>
<info name="Codec">Text subtitles with various tags (subt)</info>
</category><category name="Stream 3"><info name="Description">Forced</info>
<info name="Type">Subtitle</info>
<info name="Language">Russian</info>
<info name="Codec">Text subtitles with various tags (subt)</info>
</category>
<category name="Stream 7">
<info name="Description">SDH</info>
<info name="Type">Subtitle</info>
<info name="Language">English</info>
<info name="Codec">Text subtitles with various tags (subt)</info>
</category><category name="Stream 5"><info name="Description">Forced</info>
<info name="Type">Subtitle</info>
<info name="Language">English</info>
<info name="Codec">Text subtitles with various tags (subt)</info>
</category>
<category name="Stream 4">
<info name="Description">Full</info>
<info name="Type">Subtitle</info>
<info name="Language">Russian</info>
<info name="Codec">Text subtitles with various tags (subt)</info>
</category>
<category name="Stream 2">
<info name="Codec">A52 Audio (aka AC3) (a52 )</info>
<info name="Type">Audio</info>
<info name="Language">English</info>
<info name="Sample rate">48000 Hz</info>
</category>
</information>
</root>
为此我得到了这个xmllistmodel工作来获取数据:
XmlListModel{
id: xmlModel
query: "/root"
XmlRole{ name: "fullscreen"; query: "fullscreen/string()"}
XmlRole{ name: "aspectratio"; query: "aspectratio/string()"}
XmlRole{ name: "audiodelay"; query: "audiodelay/string()"}
XmlRole{ name: "currentplid"; query: "currentplid/string()"}
XmlRole{ name: "time"; query: "time/string()"}
XmlRole{ name: "volume"; query: "volume/string()"}
XmlRole{ name: "length"; query: "length/string()"}
XmlRole{ name: "random"; query: "random/string()"}
XmlRole{ name: "rate"; query: "rate/string()"}
XmlRole{ name: "state"; query: "state/string()"}
XmlRole{ name: "loop"; query: "loop/string()"}
XmlRole{ name: "repeat"; query: "repeat/string()"}
XmlRole{ name: "subtitledelay"; query: "subtitledelay/string()"}
XmlRole{ name: "artist"; query: "information/category/info[@name='artist']/string()"}
XmlRole{ name: "album"; query: "information/category/info[@name='album']/string()"}
XmlRole{ name: "filename"; query: "information/category/info[@name='filename']/string()"}
//Stream 0 is hard-coded :(
XmlRole{ name: "type"; query: "information/category[@name='Stream 0']/info[@name='Type']/string()"}
}
以上所有信息都很好,但我似乎无法正常获得的是多流信息。根据文件的不同,如果用户有更多的音轨或字幕,则只能有2个流甚至10个。 xmllistmodel中的最后一行我可以查找流0的类型,但之后需要进行硬编码。 我想要找到的是流号码是什么类型。
有没有办法从xml中为所有流使用qml获取此信息?
谢谢:)