Converting XML String to MessageElement array

Hi,
I am trying to call a .NET web service from my Java client. I used WSDL2Java to generate the java classes for calling the .NET web service. The generated classes to call the service expects an array of org.apache.axis.message.MessageElement objects. I have a string representing an XML document which looks like this:
String xmlString = "<Results><Adjustments><Adjustment><RebuildAdjustmentID>16</RebuildAdjustmentID><IsBasicAdjustment>true</IsBasicAdjustment><AdjustmentType>stone/AdjustmentType><Title>External walls</Title></Adjustment></Adjustments></Results>"
I have tried converting the string into an array of MessageElement objects by the following way:
MessageElement[] m = new MessageElement[1];
Document XMLDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(result2.toString())));
m[0] = XMLDoc.getDocumentElement();
However I keep getting the following message returned from the service:
"Object reference not set to an instance of an object"
I have tried a handful of ways but keep getting this same error. I have searched the web for hours looking for a solution to this problem without success so any help/ideas much appreciated,
Thanks.
Paul

Any updates on this?
I am facing a similar problem.

Similar Messages

  • Special charecters handling while Converting XML string to DOM

    Hi,
    I am using the following approach for converting XML string to DOM, but due to Special characters like "&", I am getting Exceptions:
    String xmlString;
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(xmlString)));
    Can anyone please help me out on how to handle the Special characters in the above code.

    If the XML doesn't parse, then the XML must be invalid. Show a sample of such a special character in the XML data. Please use \ tags to post the actual XML content and any other code.                                                                                                                                                                                                                                                                                                                                                                                           

  • Convert XML string into XML

    Hi All,
    Can you please let me know for any sample code in xslt/java mapping for converting XML string into XML. We use SAP Pi 7.0
    My XML string starts like this
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <ns0:MT_ReceiverFileStructure <namespace>"><Output><?xml version="1.0" encoding="ISO-8859-9"?><?xml-stylesheet type="text/xsl" href="<xsl>"?><Tarih_Date Tarih="11.09.2014" Date="09/11/2014>
       Thanks,
       Pavithra

    Thanks Praveen. It worked.
    However, the xml i have is an extract from a exchange rate URL and it has the reference to a xsl in it as below
    <?xml version="1.0" encoding="ISO-8859-9"?><?xml-stylesheet type="text/xsl" href="<ABC.xsl>"?>.
    So there is an error in sxmb_moni. Is it possible to remove this.

  • Convert XML string into DOM

    Hi all,
    I have a question here regarding converting XML string into a DOM document.
    How can I do this in Java?
    The Document.Parse() methods do not have one that takes in String as its parameter.
    I'm not sure what is the best way to do this in Java.
    Any help is greatly appreciated.
    Thank you in advance.
    regards,
    Sean

    Convert XML String to Document with StringReader.
    String xmlString;
    DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
       Document         document = builder.parse(new InputSource(new StringReader(xmlString)));

  • Convert XML string into an abap format date and time

    Hi,
    Does anyone know of a method or a function module in ABAP which converts XML string into an abap format date and time.
    Here is a part of the xml that I want to convert.
    <ns2:EventDateTime>2009-07-02T10:13:45+10:00</ns2:EventDateTime>
    <ns2:EventMessageTransmissionDateTime>2009-07-02T10:13:45.987+10:00</ns2:EventMessageTransmissionDateTime>
    Currently EventDateTime and EventMessageTransmissionDateTime are type XSDDATETIME_Z and these are converted to proper dates and times. We will be changing these fields to a STRING instead of XSDDATETIME_Z. The reason for this is to make the field more versatile. The customer would be receiving dates with Zulu (2009-09-23T12:00:00Z), with offsets (2009-09-23T12:00:00+10:00/-10:00) and just local timestamp (2009-09-23T12:00:00). With this, we need to make the date fields as string
    to be able to accept the various date formats (esp. the local timestamp).
    I am looking for a standard function module or method that will convert the xml string to a proper date and time abap format.
    Would appreciate anyone's help!
    Thanks.
    Edited by: eunice ocson on Jul 13, 2009 1:49 AM
    Edited by: eunice ocson on Jul 13, 2009 1:50 AM
    Edited by: eunice ocson on Jul 13, 2009 1:51 AM
    Edited by: eunice ocson on Jul 13, 2009 1:51 AM

    Hi Eunice
    Use the FM 'SMUM_XML_PARSE'
    for more info
    [Convert XML string to ABAP|XML String to ABAP or GUI]
    hope it helps you.
    Thanks!!

  • XML: How to convert xml string into Node/Document

    I have a string in xml form.
    <name>
    <first/>
    <second/>
    </name>
    I want to convert this string into DOM Node or Document.
    How can I do this?
    Any help or pointer?
    TIA
    Sachin

    Try this :
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new org.xml.sax.InputSource(new StringReader(strXml)));Hope this helps.

  • How to convert xml String to xml file?

    Hi,
    I got a method that do the following:
    public static String convertXmlToString(String xmlFileName) throws Exception
            File file = new File(xmlFileName);
            FileInputStream insr = new FileInputStream(file);
            byte[] fileBuffer = new byte[(int)file.length()];
            insr.read(fileBuffer);
            insr.close();
            return new String(fileBuffer);
         }The return String is the contents of an existing xml file and one example is shown below:
    <object type="server.WOXReference" id="0"><field name="actualPathObj"><object type="java.lang.String" id="1">C:\restClient\actualXMLObjects\812856084.xml</object></field><field name="object"><object type="server.WOXConstructor" id="2"><field name="className"><object type="java.lang.String" id="3">rec.SimpleRecognizer</object></field><field name="types"><array type="java.lang.String" length="3" id="4"><object type="java.lang.String" id="5">double[].class</object><object type="java.lang.String" id="6">double.class</object><object idref="6" /></array></field><field name="args"><array type="java.lang.Object" length="3" id="7"><array type="double" length="5" id="8">22.33 33.22 33.33 22.0 11.0</array><object type="java.lang.Double" id="9">2.2</object><object type="java.lang.Double" id="10">3.3</object></array></field><field name="retType"><object type="java.lang.String" id="11">act</object></field></object></field></object>
    and I want to change the above string to xml file like below:
    <object type="server.WOXReference" id="0"><field name="actualPathObj"><object type="java.lang.String" id="1">C:\restClient\actualXMLObjects\812856084.xml</object></field><field name="object"><object type="server.WOXConstructor" id="2"><field name="className"><object type="java.lang.String" id="3">rec.SimpleRecognizer</object></field><field name="types"><array type="java.lang.String" length="3" id="4"><object type="java.lang.String" id="5">double[].class</object><object type="java.lang.String" id="6">double.class</object><object idref="6" /></array></field><field name="args"><array type="java.lang.Object" length="3" id="7"><array type="double" length="5" id="8">22.33 33.22 33.33 22.0 11.0</array><object type="java.lang.Double" id="9">2.2</object><object type="java.lang.Double" id="10">3.3</object></array></field><field name="retType"><object type="java.lang.String" id="11">act</object></field></object></field></object>How to I change the above xml String back to xml file again? The appropriate tags must be taken care of like > must be > and < must be <.
    Please advice and can give me some sample code.
    Thanks.

    By writing some code that runs through the file and adds a new line for a new element using these methods here...
    http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html
    i.e.
    startDocument()
    startElement(String namespaceURI, String localName, String qName, Attributes atts)
    endDocument()

  • Converting XML string to internal table

    Hello everyone,
    I am trying to convert an XML string to an internal table. The format of the XML string is as follows:
    <node label="Compressors" NODE_ID="783" checked="1" expandStatus="false">
       <node label="Nail guns" NODE_ID="78543" checked="1" expandStatus="false"/>
       <node label="Spray guns" NODE_ID="855" checked="0" expandStatus="false"/>
       <node label="Cleaning equipment" NODE_ID="9" checked="1" expandStatus="false"/>
    </node>
    What I need is an internal table with the fields NODE_ID and checked filled. The hierarchy here doesn't matter, so I just need an internal table of a structure with 2 fields. The whole XML is hierarchical and contains only the <node> tag, which can be self-closing or not with the attributes within the tag.
    What is the best way to accomplish this?
    Performance here is quite important too, as this XML can contain over 100,000 nodes.
    Should it be done with an xpath expression, with a regex, with the iXML parser, an XSLT call transformation?
    Any help is greatly appreciated!
    Best regards,
    Vincent

    Use this FM to get into internal table
                CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
                  EXPORTING
                    im_xstring = zl_attcntx
                  IMPORTING
                    ex_string  = zl_attcont.
       SPLIT zl_attcont AT cl_abap_char_utilities=>newline INTO TABLE zit_legacy.

  • Converting XML string to ABAP types

    Hello,
    I am having a requirement where i wanted to parse incoming XML string and i checked few of examples of CALL TRANSFORMATION id.
    but whatever examples i checked those were simple transformation with no hierarchy.
    My source structure
    <record>
    <firstname>XYZ</firstname>
    <position>Testposition</postion>
    </record>
    and i used
    CALL transformation id
    source xml lv_xml
    result firstname = lv_firstname position = lv_position.
    but lv_firstname and lv_position were blank. any idea whether it can be acheived through such method?
    thanks in advance.
    regards
    rajeev

    Hello Rajeev,
    Try using the following simple transformation
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="record"/>
      <tt:template name="record">
        <record>
          <firstname>
            <tt:value ref="record.firstname"/>
          </firstname>
          <position>
            <tt:value ref="record.position"/>
          </position>
        </record>
      </tt:template>
    </tt:transform>
    In your code you could define a structure like the following:
    TYPES: BEGIN OF record,
                  firstname TYPE char50,
                  position  TYPE char50,
                END OF record.
    And now you could use the CALL TRANSFORMATION in your code to convert the xml string into the structure and visa-versa.
    CALL TRANSFORMATION zcl_test_rec
          SOURCE XML lv_string
          RESULT record = ls_test.
    Where lv_string holds the xml as a string and ls_test is defined as a structure of type record (defined above).
    Hope this helps.
    Thank you,
    Ramneek

  • I want to convert a String into an array of bytes

    I am working with telnet programming with java, where I want to convert login name and password of an online user in 'String' format to 'Bytes', plz help me. Which Input or Output Stream I can use

    Assuming you've got the username / password into a String object, you can convert it to a byte[] array using this method.
    String.getBytes();
    Look at the String API
    http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
    Hope that helps.

  • Convert xml string into xml file?

    Hi,
    I got a method that returns an JDom Element object.
    Then I use the JDOM Element toString method() to change it into xml string.
    Now, I need to convert it into actual xml file.
    How to I do it?
    Thanks.

    Hi,
    If you got an xml string, just write it to an ordinary file. Look at FileWriter.
    /Kaj

  • To convert  XML String- ResultSet

    Hi
    I am using Web Services created in EJB and will be accessed from JSP client containing applet-swing based GUI, using n tier architecture so I need to convert the XML String to Java ResultSet. (I am able to convert the ResultSet -> XML string using ResultSetBuilder), So I just want to know how to convet the XML String to Java ResultSet.
    Secondly is there any method to manually add columns to the ResultSet.
    Will anybody tell me of any utility, tools or the methods so that I can accomplish this task.
    Thank in advance
    nitin

    What would be the point of doing this? A ResultSet is basically like a cursor running against a database query. You could create a fake ResultSet and pass it something else but why? Just use a normal data-structure.

  • How to convert a String to an array

    Can somebody tell me how to convert a String to an array

    ronisto wrote:
    Can somebody tell me how to convert a String to an arrayI assume you mean to convert it into an array of the individual characters that comprise the String.
    Can you not simply look at the API documentation? Nothing in the String API jumps out at you?
    http://java.sun.com/javase/6/docs/api/index.html

  • Convert a string to an array of 16bit unsigned integers

    I have a string represented in hex format, how can I convert this to an array of 16 bit unsigned integers?
    I know I can use string to byte array to easily convert it to 8 but unsigned integers, is there a simple way for 16 bit unsigned integers?
    Solved!
    Go to Solution.

    hydzik wrote:
    I have a string represented in hex format, how can I convert this to an array of 16 bit unsigned integers?
    I know I can use string to byte array to easily convert it to 8 but unsigned integers, is there a simple way for 16 bit unsigned integers?
    While your description is somewhat vague and not very clear, I think the typecast solution from the previous poster may not be what you look for. You may more likely look for something along these lines:
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    HexToU16.png ‏17 KB

  • Convert a string to an array of character

    What would be the easiest way to convert a string "HELLO" to an array of character "H" "E" "L" "L" "O" ?
    I have a way to do it with a for loop but I'm wondering if there is nothing even more simple.
    Thanks in advance,
    Martin

    Try typecast instead.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    HELLOCast.gif ‏2 KB

Maybe you are looking for