Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am getting the xml string as given below. I am new in c#. Kindly help me to get the values and arraylist from the same xml string using serializer or deserialize.

XML
<?xml version="1.0" encoding="UTF-8"?>
    <java version="1.4.1.07" class="java.beans.XMLDecoder">
     <object class="java.util.HashMap">
      <void method="put">
       <string>RES_ERROR_DESC</string>
       <string></string>
      </void>
      <void method="put">
       <string>RES_VALUE_OUT</string>
       <object class="java.util.HashMap">
        <void method="put">
         <string>1</string>
         <object class="java.util.ArrayList">
          <void method="add">
           <string>UMESH AGARWAL  AGARWAL (MINOR)</string>
          </void>
          <void method="add">
           <string>&quot;&quot;&quot;119 COTTON ST KOLKATA-700007 &quot;&quot;&quot;
    </string>
          </void>
         </object>
        </void>
       </object>
      </void>
      <void method="put">
       <string>RES_OUT</string>
       <string>SUCCESS</string>
      </void>
     </object>
</java>
Posted
Comments
Suvabrata Roy 16-Sep-14 6:47am    
Is it a some kind of service response?
Member 10484876 16-Sep-14 7:52am    
Hi, Thanks for reply.
Yes the same xml string received from the webservice response. where they using hashmap and XMLDecoder in Java. I want to use such kind of method. I expect to get the values mentioned in string tags.
George Jonsson 16-Sep-14 7:02am    
How do you want your output to be formatted?
Member 10484876 16-Sep-14 7:53am    
Hi, Thanks for reply.
Yes the same xml string received from the webservice response. where they using hashmap and XMLDecoder in Java. I want to use such kind of method. I expect to get the values mentioned in string tags.
Or the output as Object or arraylist
George Jonsson 16-Sep-14 8:00am    
Well, I don't know Java, so I have no idea how that would look like.

1 solution

There are several strategies you could pursue, but, keep in mind that you are translating objects from Java to C#, objects that may be structurally different. Worst case is you have to write your own custom parser for Java objects that do not "map" to C# ?

1. explore serializing from Java to JSON, and then use .NET's JSON classes to de-serialize the JSON.

2. explore using the JLCA (Java Language Conversion Assistant) from Microsoft. Note: this goes "way back," and I've never used it.[^].

3. There's an April 2014 review of five tools for converting Java to C# : >[^].

I suggest you add to your question the Java source that was serialized into the XML you show.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Sep-14 10:16am    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900