Unsolved Read XML files and select info
-
Hello everyone,
I am currently developing a project in my master's thesis and need some help. I'm new to Qt Creator 4.8.2 and XML files and so I'm still trying to understand how it works. Right now I have a problem that I can not solve. I'm working with QXmlSimpleReader Class to read this xml file:<?xml version="1.0" encoding="UTF-8"?> <hdevelop file_version="1.2" halcon_version="18.11.1.1"> <procedure name="clips_orientation"> <interface> <oo> <par name="Clips" base_type="iconic" dimension="0"/> <par name="Regions" base_type="iconic" dimension="0"/> <par name="ConnectedRegions" base_type="iconic" dimension="0"/> <par name="SelectedRegions" base_type="iconic" dimension="0"/> </oo> <oc> <par name="Phi" base_type="ctrl" dimension="0"/> <par name="Area" base_type="ctrl" dimension="0"/> <par name="Row" base_type="ctrl" dimension="0"/> <par name="Column" base_type="ctrl" dimension="0"/> </oc> </interface> <body> <l>read_image (Clips, clips.png')</l> <l>draw_circle (WindowHandle, Row1, Column1, Radius)</l> <l>gen_circle (Circle, Row1, Column1, Radius)</l> <l>reduce_domain (Clips, Circle, ImageReduced)</l> <l>threshold (ImageReduced, Regions, 3, 60)</l> <l>connection (Regions, ConnectedRegions)</l> <l>select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4500, 6300)</l> <l>orientation_region (SelectedRegions, Phi)</l> <l>area_center (SelectedRegions, Area, Row, Column)</l> <l>return ()</l> </body> <docu id="clips_orientation"> <parameters> <parameter id="Area"/> <parameter id="Clips"/> <parameter id="Column"/> <parameter id="ConnectedRegions"/> <parameter id="Phi"/> <parameter id="Regions"/> <parameter id="Row"/> <parameter id="SelectedRegions"/> </parameters> </docu> </procedure> </hdevelop>
I need to read the file and return:
- All
<parameter id=>
of the<parameters>
-> Area, Clips, Column, ConnectedRegions, Phi, Regions, Row, SelectedRegions - The first word of each line of the
<body>
-> read_image, draw_circle, gen_circle, reduce_domain, threshold, connection, select_shape, orientation_region and area_center.
From now on thank you very much to who can pay attention to my problem and continuation of good programming.
Best regards, Miguel
- All
-
@MirreCap said in Read XML files and select info:
QXmlSimpleReader
Hi
they show how to use it here
http://www.informit.com/articles/article.aspx?p=1405553&seqNum=3Basically, you subclass QXmlDefaultHandler and fill out the parsing handlers.
-
@MirreCap
For your choice ofQXmlSimpleReader
, are you wedded to it, I'll just point out https://doc.qt.io/qt-5/qxmlstreamreader.html#details:QXmlStreamReader
is a faster and more convenient replacement for Qt's own SAX parser (seeQXmlSimpleReader
).QXmlSimpleReader
uses the event/callback-driven approach to parsing, which is "cumbersome" for your own code. If you can, do yourself a favour and at least move to the more convenientQXmlStreamReader
.Using
QDomDocument
+ XQuery/QXmlQuery
is even easier, but I have a feeling I have seen this/these are "no longer maintained" and you're supposed to useQXmlStreamReader
. Which is a shame/backward step for those of us who like XML.http://3gfp.com/wp/2014/07/three-ways-to-parse-xml-in-qt/ compares these 3 approaches.