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>[email protected]</Email><Name>abuse</Name><Phone>+1-800-900-0241</Phone></AbuseContact><AdministrativeContact><Email>[email protected]</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>[email protected]</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?

0

3 Answers 3

2

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

Android: parse XML from string problems

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

Try this Working with XML-Android

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.