I would use JDOM ( http://www.jdom.org ) in the following manner:

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;


import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.filter.ElementFilter;
import org.jdom.input.SAXBuilder;

/*
 * Created on Jan 5, 2005
 */

/**
 * @author Hugo A. Garcia
 */
public class ParserSpike {

        private File inputFile;

        /**
         * @param outputFile
         * @param inputFile
         * 
         */
        public ParserSpike(File inputFile) {
                super();
                this.inputFile = inputFile;
                if (!inputFile.exists()) {
                        System.out.println("The input file" + 
inputFile.getPath()
                                        + "does not exist");
                        System.exit(1);
                }
        }

        public static void main(String[] args) {
                File inputFile = new File(args[0]);
                new ParserSpike(inputFile).run();
        }

        /**
         * 
         */
        private void run() {
                Document document = null;
                URL fileURL;
                SAXBuilder builder = new SAXBuilder();
                
                try {
                        fileURL = inputFile.toURL();
                        document = builder.build(fileURL);
                        Element rootElement = document.getRootElement();
                        Iterator elementList = rootElement.getDescendants(new
ElementFilter("element"));
                        while (elementList.hasNext()) {
                                Element nextElement = (Element) 
elementList.next();
                                List attributeList = 
nextElement.getAttributes();
                                Iterator attributeIterator = 
attributeList.iterator();
                                while (attributeIterator.hasNext()) {
                                        Attribute attribute = (Attribute) 
attributeIterator.next();
                                        System.out.print(attribute.getName() + 
" = " +attribute.getValue() + " ");
                                }
                                System.out.println();
                        }
                } catch (IOException e) {
                        e.printStackTrace();
                } catch (JDOMException e) {
                        e.printStackTrace();
                }
        }
}

The Output is the following:

name = data type = int 
name = programName type = string 
name = managerHost type = string 
name = value type = string 
name = dataType type = string 
name = sensorName type = string 

-H


On Wed,  5 Jan 2005 04:06:16 -0500, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello,
> 
> I am Stefan a Grad student at UNC. I am working on research using Globus
> and other grid services platforms. I am kinda stuck with getting the data
> from MessageElement array. I have seen this mail:
> 
> http://www.mail-archive.com/axis-dev@xml.apache.org/msg09363.html
> 
> I have the same problems as the researcher. I see that she has attached a
> MessageElementHelper class and that is deleted. I have attached a slice of
> code below. Maybe you can give me some ideas how to parse the MessageElement:
> 
> MessageElement[] elements = res.get_any();
> 
> for( int i = 0; i < elements.length; i++ )
> {
>     System.out.println("Query result:");
> 
>     // an iterator over all attribute names
>     java.util.Iterator printIter = elements[i].getAllAttributes();
>     int k = 0;
>     while( printIter.hasNext( ) )
>     {
>         Name n = ( Name )printIter.next( );
>         k++;
>     }
>     Attributes att = elements[i].getAttributes( );
>     System.out.println( "len = " + att.getLength( ) );
>     System.out.println( "k = " + k );
> }
> 
> Both of the len and k are 1. I have to expand the attribute.
> 
> The service data file is:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions name="BasicSensorData"
> 
> targetNamespace="http://www.renci.org/namespaces/2004/Autopilot/BasicSensorService_sd/BasicSensorSDE";
> 
> xmlns:tns="http://www.renci.org/namespaces/2004/Autopilot/BasicSensorService_sd/BasicSensorSDE";
>         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";>
> 
> <wsdl:types>
> <schema
> targetNamespace="http://www.renci.org/namespaces/2004/Autopilot/BasicSensorService_sd/BasicSensorSDE";
>         attributeFormDefault="qualified"
>         elementFormDefault="qualified"
>         xmlns="http://www.w3.org/2001/XMLSchema";>
> 
>         <complexType name="BasicSensorDataType">
>                 <sequence>
>                         <element name="data" type="int"/>
>                         <element name="programName" type="string"/>
>                         <element name="managerHost" type="string"/>
>                         <element name="value" type="string"/>
>                         <element name="dataType" type="string"/>
>                         <element name="sensorName" type="string"/>
>                 </sequence>
>         </complexType>
> 
> </schema>
> </wsdl:types>
> 
> </wsdl:definitions>
> 
> As you may expect I need the values for all elements (data, programName,
> managerHost, value, dataType, sensorName).
> 
> Any ideas will be of great help. Thank you.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to