xml문서 doc, element로 가져오기

https://dobest51.wordpress.com/2017/06/26/java-xml%ED%8C%8C%EC%9D%BC%EC%97%90%EC%84%9C-string-data-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0/

 

 

     String response = mOAuthLoginInstance.requestApi( mContext, at, url );
                try
                {
                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                    DocumentBuilder db = dbf.newDocumentBuilder();
                    InputSource is = new InputSource();
                    is.setCharacterStream(new StringReader(response));
                    Document doc = db.parse(is);
                    Element resp = (Element) doc.getElementsByTagName("response").item(0);
//사용 방법은 아래와 같다.

                    uid = resp.getElementsByTagName("id").item(0).getTextContent();
                    name = resp.getElementsByTagName("name").item(0).getTextContent();
                    email = resp.getElementsByTagName("email").item(0).getTextContent();
                    created_at = "2017";
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s