[Solved]How can I get CDATA from xml
-
Hi all,
I'm trying to use XmlListModel to get some data from xml file.
All is well but title item is lose,here is my code:
@XmlListModel {
source: "site.xml"
query: "/urlset/url/data/display"
XmlRole { name: "website"; query: "website/string()" }
XmlRole { name: "title"; query: "title/string()" }
}@
site.xml:
<?xml version="1.0" encoding="UTF-8"?>
<urlset count="82">
<url id="1">
<data>
<display>
<website>www.mywebsite.com</website>
<title><![CDATA[[this is text what I need]]></title>
</display>
</data>
</url> -
Hi, as I see in your xml the line
@
<urlset count=“82”>
@
is not part of the quesy tree. Try querying to the next level:
@
XmlListModel {
source: "site.xml"
query: "/url/data/display"
XmlRole { name: "website"; query: "website/string()" }
XmlRole { name: "title"; query: "title/string()" }
}
@
Is possible that urlset is wrong in your file and will be
@
<urlset count=82 />
@
To have your code working I think that the xml will be:
@
<?xml version=“1.0” encoding=“UTF-8”?>
<urlset count=“82”>
<url id=“1”>
<data>
<display>
<website>www.mywebsite.com</website>
<title><![CDATA[[this is text what I need]]></title>
</display>
</data>
</url>
</urlset>@
-
Sure, I know. Te main query is needed to point the "entry" of your xml tree where you want the fields, then you can sub-query every XmlRole.
Useful the example ?