[Interest] XML parsing
Francisco Ares
frares at gmail.com
Mon Jul 17 23:21:34 CEST 2017
2017-07-17 16:50 GMT-03:00 Christoph Feck <cfeck at kde.org>:
> On 17.07.2017 21:25, Francisco Ares wrote:
>
>> Hi, all.
>>
>> I'm pretty new to programming, in special regarding XML generation and
>> parsing.
>>
>> Could anyone help me parse the following file?
>>
>>
>> <?xml version="1.0" ?>
>> <Settings Firmware="00.01.52.11715 " Name="Mako" Model="Mako G-125C
>> (5488)">
>> <Integer Name="AcquisitionFrameCount">1</Integer>
>> <Float Name="AcquisitionFrameRateAbs">3.0</Float>
>> <Enumeration Name="AcquisitionMode">SingleFrame</Enumeration>
>> </Settings>
>>
>> Meaning 3 settings in a device, one on each line that shows first the type
>> of the setting, the name to which this device's API would respond to, then
>> the new value for that setting.
>>
>> For now, I have the following, mostly from samples:
>>
>> QDomDocument doc("mydocument");
>> QFile file("myfile.xml");
>> if (!file.open(QIODevice::ReadOnly))
>> return;
>> if (!doc.setContent(&file)) {
>> file.close();
>> return;
>> }
>> file.close();
>>
>> QDomElement docElem = doc.documentElement();
>>
>> QDomNode n = docElem.firstChild();
>> while(!n.isNull()) {
>> QDomElement e = n.toElement(); // try to convert the node to an element.
>> if( ( !e.isNull() ) && n.isElement() ) {
>> QString aType = e.nodeName();
>> QString aValue = e.text();
>> }
>> n = n.nextSibling();
>> }
>>
>>
>> This returns me the the type and the value, but I could not find a way
>> to obtain the name of the setting (for instance, "AcquisitionMode" on
>> line 3.
>>
>> Any help will be highly appretiated!
>>
>> Thanks,
>> Francisco
>>
>
> Use QDomElement::attribute() or QDomElement::attributeNode().
>
Thank you! That did it.
Best regards to All,
Francisco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170717/70d63c95/attachment.html>
More information about the Interest
mailing list