0

Hy i need to parse this XML :

    <WhoisRecord xmlns="http://adam.kahtava.com/services/whois" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<DomainName>68.140.1.1</DomainName>
<RegistryData><AbuseContact><Email>abuse-mail@verizonbusiness.com</Email><Name>abuse</Name><Phone>+1-800-900-0241</Phone></AbuseContact><AdministrativeContact><Email>stephen.r.middleton@verizon.com</Email><Name>Verizon Internet Services</Name><Phone>800-243-6994</Phone></AdministrativeContact><BillingContact i:nil="true"/><CreatedDate>2002-05-13T00:00:00-04:00</CreatedDate><RawText i:nil="true"/><Registrant><Address>22001 Loudoun County Parkway</Address><City>Ashburn</City><Country>US</Country><Name>UUNET Technologies, Inc.</Name><PostalCode>20147</PostalCode><StateProv>VA</StateProv></Registrant><TechnicalContact><Email>swipper@verizonbusiness.com</Email><Name>swipper</Name><Phone>+1-800-900-0241</Phone></TechnicalContact><UpdatedDate>2004-03-16T00:00:00-05:00</UpdatedDate><ZoneContact i:nil="true"/></RegistryData></WhoisRecord>

My code looks like this:

public class XMLParser 
{


    String streamTitle = "";

    /** Called when the activity is first created. 
     * @throws IOException 
     * @throws SAXException */
    public String startparse(String xml) throws SAXException, IOException 
    {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

    try 
    {
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        builder.parse(xml);
    } 
    catch (ParserConfigurationException e) 
    {
        e.printStackTrace();  
    }

    return builderFactory.getAttribute("WhoisRecord").toString();

    }
}

when i try to return something from startparse i simple get nothing.

 XMLParser xmlpar = new XMLParser();
Log.v("Faruk TEST ", "udss:"+xmlpar.startparse(temp));

Do some one know a simple solution for this problem?

streetparade
  • 32,000
  • 37
  • 101
  • 123

3 Answers3

2

Try this i hope it is what you are looking for ...

Android: parse XML from string problems

Community
  • 1
  • 1
Vaibhav Jani
  • 12,428
  • 10
  • 61
  • 73
1

I think that your call to builderFactory.getAttribute is wrong.

DocumentBuilder.parse() returns a Document object, and this will contain the DOM that you've just parsed. You can use this to access the elements of the XML.

Mark Allison
  • 21,839
  • 8
  • 47
  • 46
0

Try this Working with XML-Android

Jignesh Dhua
  • 1,471
  • 1
  • 14
  • 31