iOS Question How do I read the attribute values of an xml element using sax parser

Discussion in 'iOS Questions' started by davepamn, Mar 23, 2015.

  1. davepamn

    davepamn Active Member Licensed User

    I need to read the attribute values of an xml element

    Code:
    Dim oList As List

    oList.Initialize
    Dim In As InputStream

        
    In = File.OpenInput(File.DirAssets, "xml_fh378692.xml")
        parser.Parse(
    In"Parser")

        
    For i=0 To oList.Size-1
            
    Log(oList.Get(i))
        
    Next

    Sub Parser_StartElement (Uri As String, Name As StringAttributes As Map)

        
    Dim sElement_Name As String
        
    Dim sPixelTop As String
        
    Dim sPixelLeft As String

        
    If Name="node" Then

            sElement_Name=
    Attributes.Get("element_name")
            sPixelTop=
    Attributes.Get("pixelTop")
            sPixelLeft=
    Attributes.Get("pixelLeft")
            oList.Add(sElement_Name & 
    " top:" & sPixelTop & " left:" & sPixelLeft)

         
    End If

    End Sub

    I can see the 
    attributes as the parser walks down the xml structure.

    I don
    't understand why Text displays the same value when the node structure is nested.
    [code]
    Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)

        
    If parser.Parents.IndexOf("node") =1 Then

            
    If Name = "node" Then

                
    Log(Text.ToString)

            EndIf

        EndIf

    End Sub
    XML Code

    Code:
    <node element_name="Positional Div Parent" key="DIV6" parent_key="root" name="tblTABLE6" type="TABLE" pixelTop="330" pixelLeft="30" border="2" width="370">

    <
    node element_name="Table Header" key="tblTABLE6_head" parent_key="DIV6">
    <
    node element_name="Table Body" key="tblTABLE6_body" parent_key="DIV6">
    <
    node element_name="Table Row" key="tblTABLE6_body_row1" parent_key="tblTABLE6_body">

    <
    node element_name="na" key="tblTABLE6_body_cell1" parent_key="tblTABLE6_body_row1" backgroundColor="#ffffff" width="350" align="left" height="25" valign="top"><node ctype="cvalue"><![CDATA[This is the data that is repeating in the End Element.  How do I get around the nesting problem?]]></node>
    </
    node>
    </
    node>
    </
    node>
    </
    node>
     
    Last edited: Apr 3, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the logs?
     
  3. davepamn

    davepamn Active Member Licensed User

    Code:
    Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)

            
    If Name = "node" Then

                oList.Add(Text.tostring)

                Text.Remove(
    0,Text.Length)

            EndIf

    End Sub
     
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