how to create an xml api that will give data to my android app

后端 未结 1 983
甜味超标
甜味超标 2021-01-26 08:32

well i have an android app that needs to be updated with data... i know what to do on android-end for xml parsing... but when i try to parse the data through the follwing xml fi

1条回答
  •  执笔经年
    2021-01-26 08:39

    You should follow the tutorial that I posted on the duplicate of this question here: Parsed XML data not retrieving in android

    Although that tutorial does not show getting attributes.

    In short, your startElement should look something like this:

    @Override
        public void startElement(String uri, String localName, String qName,
                Attributes attributes) throws SAXException {
    
              if(localName.equals("stuff")){
                String element=attributes.getValue("code");
                info.setData(element); //element will hold "firststuff" on the first execution
    
            }
        }
    

    You will need a separate if for each name you are trying to match.

    Xml files in general are referred to like this (using your naming convention):

    textValue So the if statement above will handle the lines <..."secondstuff"> etc. but you will have to add more to handle each different line.

    I strongly suggest you follow a tutorial to get this accomplished, although, you will definitely learn a lot through trial and error.

    0 讨论(0)
提交回复
热议问题