Parse XML into MessageElement

import java.io.StringReader;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.axis.message.MessageElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

public class XmlTest {
public static void main(String[] args) {
try {
MessageElement[] m = new MessageElement[1];
String xmlString = "<Results>" +
					"<Adjustments>" +
						"<Adjustment>" +
							"<RebuildAdjustmentID>16</RebuildAdjustmentID>" +
							"<IsBasicAdjustment>true</IsBasicAdjustment>" +
							"<AdjustmentType>stone</AdjustmentType>" +
							"<Title>External walls</Title>" +
						"</Adjustment>" +
					"</Adjustments>" +
					"</Results>";
Document XMLDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlString)));
//m[0] = (MessageElement) XMLDoc.getDocumentElement();
Element element = XMLDoc.getDocumentElement();
m[0] = new MessageElement(element);
System.out.println("Name = " + m[0].getName());
Iterator it = m[0].getChildElements();
while (it.hasNext()) {
	MessageElement me = (MessageElement) it.next();
	System.out.println("Name = " + me.getName());
	Iterator it2 = me.getChildElements();
	while (it2.hasNext()) {
		MessageElement me2 = (MessageElement) it2.next();
		System.out.println("Name = " + me2.getName());
	}
}

System.out.println("DONE");
} catch (Exception e) {
	e.printStackTrace();
}
}
}

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

AddThis Social Bookmark Button

Similar Posts

Comments are closed.