XML Related API!

I'm sending a request to the server which inreturn sends back a series of configuration parameters in XML format.  I have read the server responce storing it into a String variable.  Now I'd like to read through elements and altributes in order to pick the desired settings and store them in my Java DB.  What would be the API that would perform simple XML related tasks?!

Would I have to store the XML file sent by the server as a file or it's already doo that it's stored as a String?!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


read here about options:

DOM or SAX would be the most well known

SAX requires less memory (in case it matters for big files)

In case the file is small, I don't think you need to write it to file - you can
make some ByteArrayInputStream out of the XML string - didn't try it myself, but
I'm sure there are requirted methods which would read from input stream rather than ffile
snajalmAuthor Commented:
Thanks for you help so far!

So if we have an InputStream that is reading XML data off the URL connection.  How can I read this stream so that I pick an specific attribute occuring in different elements and store their values into a String array of some sort.

An example would be greatly appreciated!

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

XPath is a good candidate. Try it on a file first while you're testing and i'll show you how to do that with a stream when you've got it working

This is a rather simple example of XPath searching based on a String:

from this solution:

import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.StringReader;
import java.util.Iterator;

public class forXPath {
    public static void main(String[] args) {

        String xmlData1 = "<LoginResponse xmlns=\"http://c1.net.corbis.com/\">  " +
                   " <sessionUID>{f7be62e6-0bf5-44a7-bf77-5ab2bf307a23}</sessionUID>   " +
                     "<eNewSTok>JdKVwENgF7SbdBX2x4R+BTA/WiJatMpCJvFckhNtzbx+WZ8OqmSu+fzD36XL4irDsbp69O8YioZl6iYcwrui6NWo6dBh7YCf18A4c4Ry3nFWLpBkUt35sQmBcON1kD79+1lvdJNZrzKOQIDo3Qs/ogb95aVrp7TAgjIkugti3Q0=</eNewSTok>    " +
                   " <securityTokenXML><![CDATA[<SecurityToken><ActualMemberUID Scope=\"Public\" Type=\"Guid\" Value=\"{b7fde077-c13e-40a7-aae9-f18c5a66f3e1}\"/><EffectiveMemberUID Scope=\"Public\" Type=\"Guid\" Value=\"{b7fde077-c13e-40a7-aae9-f18c5a66f3e1}\"/><RoleID Scope=\"Public\" Type=\"Long\" Value=\"49\"/><CountryCode Scope=\"Public\" Type=\"String\" Value=\"US\"/><RegionCode Scope=\"Public\" Type=\"String\" Value=\"CA\"/><LanguageID Scope=\"Public\" Type=\"Long\" Value=\"100958\"/><OnyxSessionID Scope=\"Public\" Type=\"String\" Value=\"\"/></SecurityToken>]]></securityTokenXML>   " +

                InputSource source = new InputSource(new StringReader(xmlData1));

                XPath xPath = XPathFactory.newInstance().newXPath();

                NodeList list = null;
                try {
                    xPath.setNamespaceContext(new NamespaceContext() {
                        public String getNamespaceURI(String prefix) {
                            return "http://c1.net.corbis.com/";
                        public String getPrefix(String namespaceURI) {
                            return "ns";
                        public Iterator getPrefixes(String namespaceURI) {
                            throw new UnsupportedOperationException("Not supported yet.");

                   // list = (NodeList) xPath.evaluate("(//ns:URL128/@Value)|(//ns:ImageUID/@Value)", source, XPathConstants.NODESET);

                     list = (NodeList) xPath.evaluate("(//ns:sessionUID)|(//ns:eNewSTok)",  source, XPathConstants.NODESET);

                } catch (Exception ex) {
                for (int i = 0; i < list.getLength(); i++) {



Open in new window


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snajalmAuthor Commented:
Thanks again for all your prompt and clear response!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.