Android Question Read XML array output with key/value

Discussion in 'Android Questions' started by phukol, Jun 17, 2015.

  1. phukol

    phukol Active Member Licensed User

    Hi guys i just want to ask how can i read an XML file having key/value data using Parser? my XML has this pattern :
    Code:
    <ns1:getuserinfoResponse>
    <
    return SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
     <item xsi:
    type="ns2:Map">
        <item>
             <key xsi:
    type="xsd:string">id</key>
             <value xsi:
    type="xsd:string">26</value>
       </item>
       <item>
                 <key xsi:
    type="xsd:string">user_id</key>
                <value xsi:
    type="xsd:string"></value>
         </item>
     
  2. walterf25

    walterf25 Well-Known Member Licensed User

    What have you tried so far?

    there are plenty of examples if you do a search for XML parser.

    Cheers,
    Walter
     
  3. phukol

    phukol Active Member Licensed User

    Thanks but of course i already searched first before asking anything. I have tried this method :
    Code:
    Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
        
        
    If parser.Parents.IndexOf("getuserinfoResponse") > -1 Then 'get user info
            If Name = "HOUSE_NUM" Then
                MainMenu.strAddress = Text.ToString + MainMenu.strAddress
            
    Else If Name = "BRGY_" Then
                MainMenu.strAddress = Text.ToString + MainMenu.strAddress
            
    Else If Name = "CITY_" Then
                MainMenu.strAddress = Text.ToString + MainMenu.strAddress
            
    Else If Name = "LNAME_" Then
                MainMenu.strCardName = Text.ToString + MainMenu.strCardName
                MainMenu.strLName = Text.ToString
            
    Else If Name = "FNAME_" Then
                MainMenu.strCardName = Text.ToString + MainMenu.strCardName
                MainMenu.strFName = Text.ToString
            
    Else If Name = "MNAME_" Then
                MainMenu.strCardName = Text.ToString + MainMenu.strCardName
                MainMenu.strMName = Text.ToString
            
    Else If Name = "CARD_NUM" Then
                MainMenu.strCardNum = Text.ToString
            
    Else If Name = "EMAIL_" Then
                MainMenu.strEmail = Text.ToString 
            
    Else If Name = "TEL_NUM" Then
                MainMenu.strTel = Text.ToString 
            
    Else If Name = "maiden_name" Then
                MainMenu.strMaidenName = Text.ToString   
            
    End If
        
    End If
    End Sub
    but its not able to access the "Name" attribute. i tried comparing my logs because i was already successful in reading XML files with this format :

    Code:
    <ns1:loginResponse>
    <
    return xsi:type="SOAP-ENC:Struct">
    <result xsi:
    type="xsd:string">4</result>
    <transid xsi:
    type="xsd:string">1001312073</transid>
    <msg xsi:
    type="xsd:string">Session Created</msg>
    <session xsi:
    type="xsd:string">JDO6L913AQ779MH1CATS</session>
    </
    return></ns1:loginResponse>
    using the pattern used above
     
  4. phukol

    phukol Active Member Licensed User

    For anyone having issues with the xml pattern
    Code:
    <item>
             <key xsi:
    type="xsd:string">id</key>
             <value xsi:
    type="xsd:string">26</value>
       </item>
       <item>
                 <key xsi:
    type="xsd:string">user_id</key>
                <value xsi:
    type="xsd:string"></value>
         </item>
    what i did was modify the parser sub to this :

    Code:
    If parser.Parents.IndexOf("getuserinfoResponse") > -1 Then 'get user info
      
          
            
    If parser.Parents.IndexOf("item") > -1 Then
                
    If Name = "key" Then
                    strKey = Text.ToString
                
    Else If Name = "value" Then
                    
    If strKey = "id" Then
                        MainMenu.strID = Text.ToString
                    
    else If strKey = "HOUSE_NUM" Then
                        MainMenu.strAddress = Text.ToString & MainMenu.strAddress
                    
    Else If strKey = "BRGY_" Then
                        MainMenu.strAddress = Text.ToString & MainMenu.strAddress
                    
    Else If strKey = "CITY_" Then
                        MainMenu.strAddress = Text.ToString & MainMenu.strAddress
                    
    Else If strKey = "LNAME_" Then
                        MainMenu.strCardName = Text.ToString & MainMenu.strCardName
                        MainMenu.strLName = Text.ToString
                    
    Else If strKey = "FNAME_" Then
                        MainMenu.strCardName = Text.ToString & MainMenu.strCardName
                        MainMenu.strFName = Text.ToString
                    
    Else If strKey = "MNAME_" Then
                        MainMenu.strCardName = Text.ToString & MainMenu.strCardName
                        MainMenu.strMName = Text.ToString
                    
    Else If strKey = "CARD_NUM" Then
                        MainMenu.strCardNum = Text.ToString
                    
    Else If strKey = "EMAIL_" Then
                        MainMenu.strEmail = Text.ToString
                    
    Else If strKey = "TEL_NUM" Then
                        MainMenu.strTel = Text.ToString
                    
    Else If strKey = "maiden_name" Then
                        MainMenu.strMaidenName = Text.ToString  
                    
    End If
                
    End If
            
    End If
    i declared strKey in Sub Globals as string. Basically i check all the possible Name values and store them in strKEy, then i check for the possible values using the "next" Name value
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice