Re: BIG PROBLEM

[email protected]
Newsgroups gmane.text.xml.general
Message-ID <[email protected]>
First of all thank you. The problem is that I do not have a file. I have only
the MessageElement array. I do not read any file, or build any document. From
that I can get the iterator, but it iterates through one attribute. I need to
expand that one. The essential part in youw code that I cannot use is:

Element rootElement = document.getRootElement();
Iterator elementList = rootElement.getDescendants(new
ElementFilter("element"));

Maybe you can detaliate more this solution.

                                                                  Stefan

Quoting Hugo Garcia <[email protected]>:

> 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/[email protected]/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]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.