Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Parse XML and bind all data content to a Map <K, V>
    primarykey
    data
    text
    <p>I'm trying to develop a SOAP client &amp; 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.</p> <p><strong>My goal:</strong></p> <p>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.</p> <p><strong>e.g.</strong> I will call like as this:</p> <pre><code>String h1 = collection.get("html/body/h1"); </code></pre> <p>and h1's value should be 'StackOverflow' and come from:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;h1&gt;StackOverflow&lt;/h1&gt; &lt;p&gt;XML parsing in Java&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>etc.</p> <p><strong>My approach:</strong></p> <p>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 ) <em>key</em> would be the path of node and the <em>value</em> would be the node's or attribute's value.</p> <p><strong>e.g</strong></p> <pre><code>&lt;MethodResponse xmlns="any.xmlns"&gt; &lt;MethodResult&gt;any value&lt;/MethodResult&gt; &lt;Node1&gt; &lt;Node2&gt; &lt;Node3&gt; node3 value is here &lt;Node3&gt; &lt;/Node2&gt; &lt;/Node1&gt; &lt;respCode&gt;99&lt;/respCode&gt; &lt;respNote&gt;any value&lt;/respNote&gt; &lt;/MethodResponse&gt; </code></pre> <p>If i need to respCode in here, i would be able to call that in this way:</p> <pre><code>String respCode = map.get("/MethodResponse/respCode"); </code></pre> <p>or, to Node3:</p> <pre><code>String node3Value = map.get("/MethodResponse/Node1/Node2/Node3"); </code></pre> <p>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.</p> <p>Success criteria:</p> <p>It works for these and several different SOAP messages:</p> <ul> <li><a href="http://www.w3schools.com/xml/note.xml" rel="nofollow">http://www.w3schools.com/xml/note.xml</a></li> <li><a href="http://www.w3schools.com/xml/cd_catalog.xml" rel="nofollow">http://www.w3schools.com/xml/cd_catalog.xml</a></li> <li><a href="http://www.w3schools.com/xml/simple.xml" rel="nofollow">http://www.w3schools.com/xml/simple.xml</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/ms762271%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms762271%28v=vs.85%29.aspx</a></li> </ul> <p><strong>And my questions:</strong></p> <ol> <li>Is my approach true?</li> <li>If yes, how can i do that? Is there any working code or tutorial?</li> <li>If no, how can i do that?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload