I'm trying to develop a SOAP client & parser which is specific to our project. I've already finished the client and it invokes many kinds of (several different) SOAP web services and getting response SOAP message in XML format.
My goal:
Get the value of any node or attribute from any type of collection and it should be worked for all of my web services responses.
e.g. I will call like as this:
String h1 = collection.get("html/body/h1");
and h1's value should be 'StackOverflow' and come from:
<html>
<head></head>
<body>
<h1>StackOverflow</h1>
<p>XML parsing in Java</p>
</body>
</html>
etc.
My approach:
Now i have the response message. I want to parse it and assign all the node (and attribute) values to a collection (map) and get data from that collection. The collection's (Map ) key would be the path of node and the value would be the node's or attribute's value.
e.g
<MethodResponse xmlns="any.xmlns">
<MethodResult>any value</MethodResult>
<Node1>
<Node2>
<Node3>
node3 value is here
<Node3>
</Node2>
</Node1>
<respCode>99</respCode>
<respNote>any value</respNote>
</MethodResponse>
If i need to respCode in here, i would be able to call that in this way:
String respCode = map.get("/MethodResponse/respCode");
or, to Node3:
String node3Value = map.get("/MethodResponse/Node1/Node2/Node3");
like as XPath. But i don't want to any mapping or any Java class. I just want to access nodes (or attributes) value from its path.
Success criteria:
It works for these and several different SOAP messages:
- http://www.w3schools.com/xml/note.xml
- http://www.w3schools.com/xml/cd_catalog.xml
- http://www.w3schools.com/xml/simple.xml
- http://msdn.microsoft.com/en-us/library/ms762271%28v=vs.85%29.aspx
And my questions:
- Is my approach true?
- If yes, how can i do that? Is there any working code or tutorial?
- If no, how can i do that?
Java JAXB.