xml - xmlns : android parsing -


i trying parse below xml data. need d:messageid , d:serialnumber.

<feed xmlns="http://www.w3.org/2005/atom" ...> <script id="tinyhippos-injected"/>     <id>...</id>     <title type="text">viewerror</title>     <updated>2015-08-25t01:41:55z</updated>     <author>...</author>     <link href="edi_viewerror" rel="self" title="edi_viewerror"/>     <entry>...</entry>     <entry>...</entry>     <entry>         <id>             serveraddress         </id>         <title type="text">viewerror('abcdefg')</title>         <updated>2015-08-25t01:41:55z</updated>         <category term="viewerror" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>         <link href="viewerror('gstu7417706')" rel="edit" title="viewerror"/>         <content type="application/xml">             <m:properties   xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">                 <d:messageid>msgid_1</d:messageid>                 <d:serialnumber>sernr_1</d:serialnumber>             </m:properties>         </content>     </entry>     </feed> 

how can achieve this? android code below.

http part:

httpclient httpclient = new defaulthttpclient(); string user = "username"; string pwd = "pass"; httpget httpget = new     httpget("properhttplink"); httpget.addheader("auth header"); httpresponse response = httpclient.execute(httpget); httpentity entity = response.getentity(); inputstream = entity.getcontent(); 

parser part:

xmlpullparserfactory xmlfactoryobject = xmlpullparserfactory.newinstance(); xmlpullparser myparser = xmlfactoryobject.newpullparser(); myparser.setinput(is, null); string dee; int event = myparser.geteventtype(); while (event != xmlpullparser.end_document) {     string name=myparser.getname();     switch (event){         case xmlpullparser.start_tag:             break;         case xmlpullparser.text:             break;         case xmlpullparser.end_tag:             if(name.equals("d")){                 dee =  myparser.getattributevalue(null,"value");             }             break;     }     event = myparser.next(); } 

please note myparser.geteventtype() returns "0" , myparser.getname() returns "null".

first: name of tag messageid, not d. d namespace of tag; namespaces used distinguish between tags have same name different meanings. if there no other uses messageid in document (i.e. never see other namespace elsewhere), can ignore it.

if ("messageid".equals(parser.getname())) { 

or, if namespace matter

if ("d".equals(parser.getnamespace()) && "messageid".equals(parser.getname())) { 

second: code uses getattributevalue(), content trying read text content of tag, not attribute of tag. should using gettext() (if current event text) or nexttext() (if current event start_tag). leads to...

third: can't read text end_tag event.

here's start parser code:

xmlpullparserfactory xmlfactoryobject = xmlpullparserfactory.newinstance(); xmlpullparser parser = xmlfactoryobject.newpullparser(); parser.setinput(is, null); string dee; int event; while ((event = parser.next()) != xmlpullparser.end_document) {     switch (event) {         case xmlpullparser.start_tag:             if ("messageid".equals(parser.getname()) {                 dee = parser.nexttext();             }             break;          // todo: other event types, if care them      } // end switch } // end while 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -