Parsing XML and get the attributes of a tag

Hello

When parsing XML for application of Cascades in C++, I am able to get the value of a tag as follows:

00000

But I also want to get the attributes of a tag:

But I don't know how to get the 'CA' and 'California' attributes with my current code.  Can anyone help?  Here is the code I use to parse the XML code:

void CMController::requestFinished(QNetworkReply* reply) {

    if (reply->error() == QNetworkReply::NoError) {

        QXmlStreamReader xml;

        QByteArray data = reply->readAll();
        xml.addData(data);

        QString zip;
        QString id;
        QString location;

        while (!xml.atEnd() && !xml.hasError()) {

            /* Read next element.*/
            QXmlStreamReader::TokenType token = xml.readNext();

            /* If token is just StartDocument, we'll go to next.*/
            if (token == QXmlStreamReader::StartDocument) {
                continue;
            }

            /* If token is StartElement, we'll see if we can read it.*/
            if (token == QXmlStreamReader::StartElement) {

                if (xml.name() == "zip") {
                    zip = xml.readElementText();
                }

                if (xml.name() == "id") {
                    ???
                }

                if (xml.name() == "location") {
                    ???
                }

            }

        }

        emit succeeded(result);

    } else {
        emit failed();
    }

    reply->deleteLater();

}

Thank you!

I found a working example:

if(xml.name() == "state"){
    QXmlStreamAttributes attrib = xml.attributes();
    QStringRef ref = attrib.value("location");
    qDebug() << "location: " << ref;
}

Tags: BlackBerry Developers

Similar Questions

  • Parsing XML and get the required data only using PLSQL

    Hi friends,

    I have a XML data

    < MAJOR_LINE >

    < LINEID > 143424538 < / LINEID >

    nom_element < ITEMNAME > = < / ITEMNAME >

    < > 78245 ITEMPATH < / ITEMPATH >

    < QUANTITY > 10 < / QUANTITY >

    < MINORLINE >

    < LINEID > 143424799 < / LINEID >

    TCC_ITEM_NAME < ITEMNAME > < / ITEMNAME >

    < > 78245 ITEMPATH < / ITEMPATH >

    < QUANTITY > 10 < / QUANTITY >

    < MINORLINE LINEID = "123456_line_id" xmlns = "xxyyzz" >

    < message > < / message >

    < status > < / status >

    < covered_Product_line_id > '123_coveredProductLineID '.

    < / covered_Product_line_id >

    < itemName > < / itemName >

    < quantity > < / quantity >

    "< service lineId ="456_service_line_id">."

    "< covered_Product_line_id >"123_coveredProductLineID"

    < / covered_Product_line_id >

    < productAttributes / >

    < itemType > < / itemType >

    < itemPath > < / itemPath >

    < coveredProducts childProductLineId = "" / > "

    < / coveredProducts >

    < parentCoverage / >

    < / service >

    < / MINORLINE >

    < / MINORLINE >

    < / MAJOR_LINE >

    I want to extract only the Covered_product_line_id and the Service_line_id of the above XML format, these data can come from any where in the xml file and the xml can be any length.

    First we need to find the covered_product_line_id and the service_line_id associated with line_id, (as I pointed out in bold) here only a single pair i showed, but it can be in any number. (Note the line_id is inside the tag).

    #PLSQL

    Help, please.

    Thanks in advance

    Hey Odie,

    Me do string literal too long error:

    Select x.*

    from xmltable)

    XmlNamespaces(default ')

    , ' for $i in //serviceLine

    , $j in $i / coveredProduct

    Returns the element r {}

    $i / lineId

    , $j/childProductLineId

    }'

    from xmltype (')

    45146937

    N20

    1

    63090598

    CON-S

    1

    SNT

    UCS - IOM

    342544294

    N20-FW012

    342544295

    342544294

    UCS-IOM2

    1

    N20-C6508-UPG:

    45146937

    CON-S

    1

    SNT

    342544295

    N20-FW012

    1

    N20-C6508-UPG:

    45146937

    CON-SN

    1

    SNT

    342544296

    FET - 10G

    16

    N20-C6508 - UPG:U SC EXPERIENCE

    342544297

    UCSB-5108-PKG-FW

    1

    N20-C6508-UPXPANSION O

    342544298

    N20-CBLKP

    2

    N20-C6508 - UPG:0 - CBLKP

    342544299

    N01-UAC1

    1

    N20-C6508 - UPG:N01 - UAC1

    342544300

    N20-CBLKI

    1

    N20-C6508 - UPG:U HC EXPANSION OPT: N20-CBLKI

    342544301

    N20-FAN5

    8

    N20-C6508 - UPG:U HC EXPANSION OPT: N20-FAN5

    342544302

    N20-CBLKB1

    6

    N20-C6508-UPG-CBLKB1

    342544303

    N20 - CAK

    1

    N20-C6508-OPT: N20 - CAK

    342544304

    UCSB-B420-M3-D

    1

    N20-C6508-UP-B420-M3-D

    63090594

    CON-SNT-B420M3D

    1

    SNT

    UCS-UC-E5-4617

    342544305

    UCS-ML-1X324RY-A

    342544306

    342544305

    UCS-UC-E5-4617

    2

    N20-C6508 - UPG:PU - E5-4617

    342544304

    CON-SNT-B420M3D

    1

    SNT

    342544306

    UCSRY-A

    2

    N20-C624RY-A

    342544304

    CON-SNT-B420M3D

    1

    SNT

    342544307

    UCS0MS

    1

    N FIO-1600MS

    63090595

    CON-SNT-FIOB16MS

    1

    SNT

    342544308

    N2KD

    4

    N20-C6LKD

    342544309

    UCSB-HS-01-EP

    2

    N20-C65B-HS-01-EP

    342544310

    N1K-VSG-UCS-BUN

    1

    N20-C6508 - UPG:U-BLA1K-VSG-UCS-BUN

    342544311

    VSG-VLEM-UCS-1

    1

    N20-C6508 - UPG:U BLN1K BUN: VSG-VLEM-UCS-1

    63090596

    CON-SAU-VSGUCS

    1

    SAU

    342544312

    N1K-VLEM-UCS-1

    1

    N20-C6508CS-BUN: VMW N-UCS-1

    63090597

    CON-SAU-VLEMUCS

    1

    SAU

    342544313

    UCSB-ACDV

    2

    N20ACDV

    342544314

    R2XX-DMYMPWRCORD

    2

    PWRCORD N20 - C6

    ')

    columns for the ordinalite seq_id

    , path number child_product_line_id "childProductLineId".

    , service_line_id number path "lineId.

    ) x ;

  • Parsing xml and store the details in the hierarchical tables

    Hi all

    I'm trying to parse a xml code and store the details in the hierarchical tables, however, I am unable to analyze the child attributes of tags and store the details in relational format.

    Oracle - 11.2.0.4 version

    My XML looks like in below:

    <Root>
    <ParentTag name="JobName" attrib1="Text" attrib2="SomeOtherText">
      <ChildTag childAttrib1="SomeValue1" childAttrib2="SomeValue2" />
      <ChildTag childAttrib1="SomeValue3" childAttrib2="SomeValue4" />
      <ChildTag childAttrib1="SomeValue5" childAttrib2="SomeValue6" />
    
      <OtherChildTag childAttrib1="SomeValue1" childAttrib2="SomeValue2" />
    </ParentTag>
    </Root>
    
    

    The table structure is as follows:

    create the table parent_details
    (
    job_id number primary key,
    VARCHAR2 (100) job_name,.
    job_attrib1 varchar2 (100),
    job_attrib2 varchar2 (100)
    );

    create the table child_details
    (
    child_id number primary key,
    number of parent_job_id
    child_attrib1 varchar2 (100),
    child_attrib2 varchar2 (100),
    Constraint fk_child_details foreign key (parent_job_id) refers to parent_details (job_id)
    );

    After analysis, I would expect the data to be stored in the format below:

    Table Name:-
    parent_details
    ID Name     Attribute1  Attribute2
    1  JobName  Text        SomeOtherText
    
    
    ChildTable (Store Child Tag details)
    ID Parent ID Attribute1  Attribute2
    1  1         SomeValue1  SomeValue2
    2  1         SomeValue3  SomeValue4
    3  1         SomeValue5  SomeValue6
    
    

    I tried following SQL, but it does not work. Please suggest if the same SQL can be improved to get the details in the expected format or should I use another solution.

    select job_details.*
      from test_xml_table t,
           xmltable ('/Root/ParentTag'
                      passing t.col 
                      columns 
                        job_name varchar2(2000) path '@name',
                        attribute1 varchar2(2000) path '@attrib1',
                        attribute2 varchar2(2000) path '@attrib2',
                        childAttribute1 varchar2(2000) path '/ChildTag/@childAttrib1'
                    ) job_details;
    

    I'm not forced to have a SQL solution, but would if it can be in SQL.

    Kind regards

    Laureline.

    Post edited by: Jen K - added the SQL, I tried to build.

    Well, the XML contains hierarchical data, and SQL is a "dish" of data, so it's up to you to treat lines that are coming out of the flat style and determine how to get that in separate tables.

    Suppose that we have several nodes of ParentTag each containing several nodes of ChildTag...

    SQL > ed
    A written file afiedt.buf

    1 with t (xml) as (select xmltype ('))
    2
    3
    4
    5
    6
    7

    8
    9
    10
    11
    12

    13
    ') of double)
    14-
    15 end of test data
    16-
    17 select x.p
    18, x.name, x.attrib1, x.attrib2
    19, including
    20, y.childattrib1, y.childattrib2
    21 t
    22, xmltable ('/ Root/ParentTag ')
    23 passage t.xml
    p 24 columns for ordinalite
    25, path name varchar2 (10) '. / @name'
    26, path of varchar2 (10) of attrib1 '. / @attrib1 '


    27, way to varchar2 (10) of attrib2 '. / @attrib2 '
    28 children xmltype road '.'
    29                 ) x
    30, xmltable ('/ ParentTag/ChildTag ')
    passage 31 x.children
    c 32 columns for ordinalite
    33, path of varchar2 (10) of childattrib1 '. / @childAttrib1 '
    34 road of varchar2 (10) of childattrib2 '. / @childAttrib2 '
    35*                ) y
    SQL > /.

    P NAME ATTRIB1 ATTRIB2 C CHILDATTRI CHILDATTRI
    ---------- ---------- ---------- ---------- ---------- ---------- ----------
    1 text JobName SomeOtherT 1 SomeValue1 value2
    1 text JobName SomeOtherT 2 SomeValue3 SomeValue4
    1 text JobName SomeOtherT 3 SomeValue5 SomeValue6
    JobName2 TextX SomeOtherT 1 SomeValue6 SomeValue8 2
    JobName2 TextX SomeOtherT 2 SomeValue7 SomeValue9 2

    Using the 'ordinalite' gives us the line number for this node in the XML file, so that you can identify each parent as well as to say who is the first record of this parent (because it will have a child with the ordinalite 1).

    An INSERT ALL tuition assistance we can insert into two different tables at the same time to keep related data... for example

    SQL > create table tbl1 (pk number, name varchar2 (10), attrib1 varchar2 (10), attrib2 varchar2 (10))
    2.

    Table created.

    SQL > create table tbl2 (parent_pk number, attrib1 varchar2 (10), attrib2 varchar2 (10))
    2.

    Table created.

    SQL > insert all
    2 when c = 1 then
    3 in the tbl1 (pk, attrib1, attrib2)
    4 values (p, attrib1, attrib2)
    When 5 1 = 1 then
    6 in the tbl2 (parent_pk, attrib1, attrib2)
    7 values (p, childattrib1, childattrib2)
    8 with t (xml) as (select xmltype ('))
    9
    10
    11
    12
    13
    14

    15
    16
    17
    18
    19

    20
    ') of double)
    21 select x.p
    22, x.name, x.attrib1, x.attrib2
    23, including
    24, y.childattrib1, y.childattrib2
    25 t
    26, xmltable ('/ Root/ParentTag ')
    27 passage t.xml
    p 28 columns for ordinalite
    29, path name varchar2 (10) '. / @name'
    30, path of varchar2 (10) of attrib1 '. / @attrib1 '
    31, path of varchar2 (10) of attrib2 '. / @attrib2 '
    32 children xmltype road '.'
    33                 ) x
    34, xmltable ('/ ParentTag/ChildTag ')
    passage 35 x.children
    c 36 columns for ordinalite
    37, path of varchar2 (10) of childattrib1 '. / @childAttrib1 '
    38, path of varchar2 (10) of childattrib2 '. / @childAttrib2 '
    39                 ) y
    40.

    7 lines were created.

    SQL > select * from tbl1;

    PK ATTRIB1 ATTRIB2 NAME
    ---------- ---------- ---------- ----------
    1 text JobName SomeOtherT
    2 JobName2 TextX SomeOtherT

    SQL > select * from tbl2.

    PARENT_PK ATTRIB1 ATTRIB2
    ---------- ---------- ----------
    1 SomeValue1 value2
    1 SomeValue3 SomeValue4
    1 SomeValue5 SomeValue6
    SomeValue6 2 SomeValue8
    SomeValue7 2 SomeValue9

  • To get the attributes of node of a node using a DOM parser

    Hi, is there an easier way to obtain the attributes of a node using a DOM parser. I do not understand the method getAttributes() because it returns NamedNodeMap where are all the getters return a node. I have just this simple xml structure:

    EditField
    First name

    For example, I am able to do "editfield" and "First name" but I want to be able to get the id attribute of matching nodes as well. The just getNodeValue() returns me null and getLocalName() and getNodeName() returns just me TYPE or a QUESTION.

    Any help please if anyone knows. Oh and I don't want to use the DOM, SAX parser. Thank you very much in advance

    I discovered how to get the attributes after some Google search and changes. It's here

    NamedNodeMap attributes = (NamedNodeMap) tempNode.getAttributes ();
    for (int = 0; g g< attributes.getlength();="" g++)="">
    Attribute attr = (Attr) attributes.item (g);
    System.out.println ("attribute:" + attribute.getName () +)
    ("with the value" + attribute.getValue ());
    }

    You do not have to use NamedNodeMap, I did not know how before. You go around casting too. Awesome, I didn't use SAX after all now

  • Try to use casStubs.jar classes and get the parameters of the analysis

    I went into class files available in casStubs.jar and was trying to come up with a script in the AppConfig.xml to connect to the CAS server and get the State of analysis and measures. I tried this option because the com.endeca.eac.toolkit.component.cas.ContentAcquisitionServerComponent class gives me these features.

    + < id script = "CheckCrawlStatus" > +.
    + < bean-shell-script > <! [CDATA [+]

    Import javax.xml.namespace.QName;
    com.endeca.cas.wsdl import. *;


    final String wsdlUrl = "http://" "${cas.host} '+': ' + ' ${cas.port} ' + ' / case? WSDL "; +
    final name of QName = new QName ("http://endeca.com/itl/cas/2010-07", "CasCrawlerService");
    CasCrawlerServiceLocator service = new CasCrawlerServiceLocator (wsdlUrl, name);
    CasCrawler robot = service.getCasCrawlerPort ();

    String crawlName = "myFirstCrawl";
    CrawlId crawlId = new CrawlId (crawlName);

    Metric [] metricArray = crawler.getMetrics (crawlId);
    + / / rest of the code to retrieve the crawl settings.

    +] > < / bean-shell-script > +.
    + < /script > +.

    Unfortunately, I still get connection refused to exception: ' java.net.ConnectException: connection refused ". My wsdl case load properly in my browser.
    Any ideas on gaps in the code or the missing configuration in the CASE or DT or platformservices?

    Thank you
    Dev

    Try to explicitly set endpoint to service before obtaining the port. So, if you connect to localhost:8500:

    service.setCasCrawlerPortEndpointAddress ("http://localhost:8500/AR"); ")

    You can substitute your host/port settings. This call is normally done through the box tool component wrappers, but since you are directly using the stubs of service, you will need to set the end point. Without this, the stubs use a test port that do not match your.

    Best
    Brett

  • Can not good press the mouse on the name of the file and get the option of e-mail

    Can not good press the mouse on the name of the file and get the option of e-mail

    Hello! If I understand your question, you want to right-click on a file and attach it in Mail. To do this, click on the file with two fingers on the touchpad, or control + click on the file, select 'Share', then 'mail '.

    I hope this helps!

  • I can't sync my phone to my computer and get the message that my phone doesn't have the latest version of Itunes. I downloaded the latest version on my mac, but what I do on my phone. I'm used to be able to synchronize the two.

    I am more able to sync my I phone on my Mac and get the message that my phone cannot be used because it requires a newer version of iTunes. He tells me to go to www.itunes.com to download the latest version of iTunes... I downloaded the latest version on my mac, but what I do on my phone? I used to be able to sync the two and now I can't even download the photos from my phone on my mac...

    iOS9 on a mobile device requires iTunes 12.3 or higher, which in turn requires a computer running OSX 10.8.5 or higher.  Update of the system only checks the updates for the current version of the system you run, but that itself can be updated.  It may or may not be possible to upgrade your computer to the system requirements. Find your computer on the web site of http://www.everymac.com model and near the bottom of the specification of the system section, he will tell what versions of the operating system, it is able to run. If you can not run a newer system, you will not be able to sync this phone to your current computer. If she can run 10.8.5 or higher, you can either buy a download for Apple OSX 10.8 Mountain Lion code online, or you can try to install the free El Capitan OSX 10.11.  El Capitan can run slower on older machines and require the additional purchase of RAM.  Making a big jump in versions of system is also more likely to affect the old software.

    At el capitan Snow Leopard, it will make my macbook is slow?  - https://discussions.apple.com/thread/7412959

    Mountain Lion 10.8 purchase link United States of America - http://www.apple.com/shop/product/D6377Z/A/os-x-mountain-lion

    Mountain Lion 10.8 purchase link U.K. - http://www.apple.com/uk/shop/product/D6377ZM/A/os-x-mountain-lion

    Course OSX Upgrade General information, including configuration required - http://www.apple.com/osx/how-to-upgrade/

  • photos has not been loaded for weeks (usually the browser chrome on PC windows at work).  I tried now on some other computers and get the same error message and I report every time.  can I do or just wait for someone to fix it

    photos has not been loaded for weeks (usually the browser chrome on PC windows at work).  I tried now on some other computers and get the same error message and I report every time.  is there anything I can do or just wait for someone to fix it?

    If you want any help here, you'll have to tell us what the error message.

    Which report you errors to?

  • Today cell 9.7 Pro wifi iPad receipt. No SIM card installed. I guess I can go to the carrier and get the SIM on their part is there a reason I would need the Apple SIM card?

    I got my Pro iPad with wifi and cell phone. There was no SIM card. I'll go to the carrier and get the card SIM on their part is there a reason I need Apple SIM card?

    Apple SIM card to activate the iPad with more companies that I believe except Sprint - if you can get a SIM card from your service provider, then you would not fail the card SIM Apple

  • Outlook Express keeps trying to compact my messages. I'm unable to post messages and get the Error 0x800ccc0d code and I can not remove outlook Express

    Outlook Express keeps trying to shoot my messages several times per day.
    I'm unable to view messages in Outlook Express and get the code of Error 0x800ccc0d
    I'm unable to remove Outlook Express from my computer, I did not need it that I use Windows live mail.
    Any ideas on how to stop this nuisance.

    Windows Search is installed?

    You must tell Windows Search to stop indexing OE.

    In the control panel. Indexing Options. Change. Clear the check box for Outlook Express.

  • Cannot print the income tax from 2012 on a Lexmark X 1185 and get the message "Prop Res DLL was not loaded"

    Original title: "Prop Res DLL not loaded".

    Try printing the income tax from 2012 on a Lexmark X 1185 and get the message "Prop Res DLL not loaded" How can I load it? Typically get this message when I print review copy. My system is Windows XP.32 bits

    Hi Robert,.

    I would be grateful if you could answer the following questions:

    1. did you of recent changes made to your computer?

    2. which antivirus app do you use?

    Here are a few troubleshooting steps that you can try to solve this problem.

     

    Method 1: Let's uninstall and reinstall the Lexmark X 1185 printer drivers.

    To uninstall the printer software, see the following link.

    http://support.Microsoft.com/kb/307895


    Restart the computer, visit the following link and install the printer drivers.

    http://support.Lexmark.com/index?ProductCode=LEXMARK_X1185&page=product&searchID=1368834464501&locale=en&UserLocale=en_US#1

    If the method above does not work, follow the steps in the next method.

    Method 2: Error Message When you try to print or save a document in OneNote 2007 or in Word 2007: "Prop Res DLL not loading" or "Cannot load Library DLBAPRP.dll"

    http://support.Microsoft.com/kb/918730

    Note: suggested above steps are applied to your scenario as well.

     

    If you have additional problems, please reply to this post and we will be happy to help you further.

  • Windows XP trying to update and get the error: another installtion progresses.

    original title: Windows XP, try to update and get the error: another installtion progresses.   That all before you proceed with this installation. How can I know what is the installation and the status?

    Windows XP trying to update and get the error: "another installtion progresses.   That completes before proceeding with this installation. "How can I know what is the installation and the status?

    Hello

    1. are you referring to Windows update?
    2 have you made changes on the computer before this problem?

    Please answer these questions and to provide more specific information on the issue. This could help us help you better.

    You can check the question in the clean boot state.

    From your computer by using a minimal set of drivers and startup programs so that you can determine if a background program is interfering with your game or program. This type of boot is known as a "clean boot".

    Reference:
    How to configure Windows XP to start in a "clean boot" State
    http://support.Microsoft.com/kb/310353

    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:
    a. click Startand then click run.
    b. type msconfigand click OK.

    The System Configuration Utility dialog box appears.

    c. click on the general tab, click Normal Startup - load all device drivers and services and then click OK.
    d. When you are prompted, click on restart to restart the computer.

  • KB2656374 update failed to install and get the error code 80070020

    Try to install update KB2656374 and get the error code 80070020. How can I fix this please?

    Hello

    1. who is the antivirus installed on the computer program?

    2 have you made any changes to the computer before the show?

     
     

    Perform the steps described in the article:

    You receive error 0 x 80070020 when you use the Windows Update Web site or the Microsoft Update Web site to install the updates

    http://support.Microsoft.com/kb/883825

     
    WARNING: Antivirus software can help protect your computer against viruses and other security threats. In most cases, you should not disable your antivirus software. If you need to disable temporarily to install other software, you must reactivate as soon as you are finished. If you are connected to the Internet or a network, while your antivirus software is disabled, your computer is vulnerable to attacks.
     
     

    I hope this helps.

  • I'm running Windows SP2 of Visa and get the following message is displayed at startup: "sasnative32 file not found Autocheck ignored."

    sasnative32 not found

    I'm running Windows SP2 of Visa and get the following message is displayed at startup:

    'sasnative32 file not found that autocheck ignored. '

    I found this message in the registry and deleted but it keeps reappearing.

    It does not seem to cause operational problems, but I want to fix.  Any suggestions?

    The BootExecute key should contain autocheck autochk *. This measure of Chkdsk to run at startup.

    You have all Tune Up or optimization programs installed? It is possible, it is distributed with a different brand.

    You can determine what is written in the registry key by using the Process Monitor program

    http://TechNet.Microsoft.com/en-us/Sysinternals/bb896645

    If you have not used before, there is an introduction to use it here:

    Windows Sysinternals Primer: Process Explorer, Process Monitor and more. Tech· Ed 2010 North America | Channel 9

    If the value has been restored in the register at the time wherever you can connect, you will need to use logging to start. This can significantly slow down the boot.

    You may be able to determine what is responsible for disabling the departure of items using msconfig.

    http://support.Microsoft.com/kb/929135

  • Microsoft Office 2010 on Vista program and get the error message 1406

    I am trying to download Microsoft Office 2010 on Vista program and get the 1406 - Setup cannot write the value to the registry key. 13DE4A42 etc. I get the message on 1406 error and it say the usere has no full control access.  I have change the access if the user has an option of full control. But the error message 1406 always happens.  What can I do else?

    What do you mean 'upload '?

Maybe you are looking for