Xpath query depenedent on new line chars

Hi,
I am trying to run an XPath query against a String which contains the XML. I am using Apache Commons IOUtils
to convert String to InputStream
If the String contains new line chars in it then I get unexpected results. However if XML is one looong string then there
is no problem.
What can I do to avoid this problem.
     public static void main(String[] args)
               throws XPathFactoryConfigurationException,
               XPathExpressionException, ParserConfigurationException,
               SAXException, IOException {
          // System.out.println(XML);
          XPathFactory xpathFactory = XPathFactory
                    .newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI);
          XPath xpath = xpathFactory.newXPath();
          DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder();
                // Use XML_STRING as the xml to reproduce the error
          Document document = documentBuilder.parse(IOUtils.toInputStream(XML_STRING));
          NodeList xpathResult = (NodeList) xpath.evaluate("/Envelope/Body",
                    document, XPathConstants.NODESET);
          Node node = xpathResult.item(0).getFirstChild();
          String requestName = node.getNodeName();
          requestName = requestName.split(":",-1)[1];
          System.out.println(requestName);
          String sessionIdXqry = "/Envelope/Body/" + requestName + "/sessionId";
          System.out.println(sessionIdXqry);
          String sessionId = (String)xpath.evaluate(sessionIdXqry, document, XPathConstants.STRING);
          System.out.println("SessionID = " + sessionId);
     }

You can't call methods in EL like that - write a custom tag that transforms the data in the way you want (replacing newlines with "<br>"). Then:
<something:yourNewTag text="${row.description}" />

Similar Messages

  • How to add EOL(new line char) to JCheckBox's text??

    I need to add new line char to JCheckBox's text.
    I have a string and I am adding new line char("\n") to that. Then I set that string as the text for JCheckBox. But it is not adding a new line. If you know the solution to this problem, please let me know.
    thanks
    amit

    hi artntek,
    thanks works well. However Since I have 3 or 4 lines (might have even more) of text for JCheckBox, JCheckBox is aligned to middle of text. Is there any way to align it with the top of the text??
    amit

  • How to insert new line char while writing bytes into file

    Hello Sir,
    Is it possible to insert the new line character in set of String variables and stored them into bytearray ,then finally write into File?
    This is the sample code which i tried:
                 File f = new File(messagesDir,"msg" + msgnum + ".txt");
                 FileOutputStream fout = new FileOutputStream(f);
                    String fromString = "From:    "+msg.getFrom()+"\n";
                    String toString = "To:     "+msg.getTo()+"\n";
                    String dateString = "Sent:    "+msg.getDate()+"\n";
                      String msgString =msg.getBody()+"\n";
                    String finalString=fromString+toString+dateString+msgString;
                    byte[] msgBytes = finalString.getBytes();
                    fout.write(msgBytes);
                 fout.close();in the above code , i tried to add the new line as "\n" in end of each string. but when i look into the generated files msg1.txt , it contains some junk char [] .
    please provide me the help
    regards
    venki

    but it has still shown the the junk char, its not able
    to create the new line in the created file i am afraid
    how am i going to get the solution?:(Do not be afraid dear sir. You are obviously using a windows operating system or a mac operating system. On windows a newline is "\r\n" not '\n', and on a mac a newline is '\r', not '\n'. If you make that correction, dear sir, your program will work.
    However, there is a better way. First, you probably want to buffer your output if you are going to write more than one time to the file, which will make writing to the file more efficient. In addition, when you buffer your output, you can use the newLine() method of the BufferedWriter object to insert a newline. The newline will be appropriate for the operating system that the program is running on. Here is an example:
    File f = new File("C:/TestData/atest.txt");
    BufferedWriter out = new BufferedWriter(new FileWriter(f) );
    String fromString = "From: Jane";
    out.write(fromString);
    //Not written to the file until enough data accumulates.
    //The data is stored in a buffer until then.
    out.newLine();
    String toString = "To: Dick";
    out.write(toString);
    out.newLine();
    String dateString = "Sent: October 27, 2006";
    out.write(dateString);
    out.newLine();
    out.close(); 
    //Causes any unwritten data to be flushed from
    //the buffer and written to the file.

  • How do i read new line char in jtextarea.getText()?

    guys, how do i read new line character in jTextArea.getText()? i'll appreciate ur help tnx..:))

    Use a StringRead, then you can treat the text file a file.

  • How to insert new line break in XSLT mapping

    Hi experts,
    I am doing file to mail scenario, i am sending the text file as an attachment using reciever mail adapter.
    I did everything, i can able to send the mail with text file attachment, but with in the file i got multiple rows, i need to put line break in XSLT mapping.
    I did use following statement but it is inserting small rectangle between the records, the records are not separating with new lines, all are in one line.
    <xsl:text>*#xA;</xsl:text>   
    note: in real coding replace * with &
    Can anyone suggest me how to insert new line in XSLT mapping.
    My XSLT mapping as look like:
    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns0="http://www.Coj.co.za/SapIsuToABSA/DirectDebitFile">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:variable name="break">&lt;br/&gt;</xsl:variable>
    <xsl:variable name="space"> </xsl:variable>
    <xsl:variable name="newline"><xsl:text></xsl:text></xsl:variable>
    <xsl:template match="/">
    <ns1:Mail xmlns:ns1="http://sap.com/xi/XI/Mail/30">
    <Subject>Please Check Attached Direct Debit File</Subject>
    <From>S@za</From>
    <To>P@za</To>
    <Content_Type>text/plain</Content_Type>
    <Content>
    <xsl:for-each select="MT_SapIsuToABSA_DirectDebitFile/DirectDebitRec/Body">
    <xsl:value-of select="Space1"/>
    <xsl:value-of select="Cust_AccNo"/>
    <xsl:value-of select="Reserve_1"/>
    <xsl:value-of select="Cust_Name"/>
    <xsl:value-of select="Cust_Name1"/>
    <xsl:value-of select="Cust_Bank_AccNo"/>
    <xsl:value-of select="Space2"/>
    <xsl:value-of select="Cust_Bank_BranchNo"/>
    <xsl:value-of select="Reserve_2"/>
    <xsl:value-of select="Space3"/>
    <xsl:value-of select="Cust_AccNo_1"/>
    <xsl:value-of select="Space4"/>
    <xsl:value-of select="Reserve_3"/>
    <xsl:value-of select="Deduction_Amnt"/>
    <xsl:value-of select="Space5"/>
    <xsl:value-of select="Reserve_4"/>
    <xsl:value-of select="Space6"/>
    <xsl:value-of select="Action_Date"/>
    <xsl:value-of select="Space7"/>
    <xsl:value-of select="Reserve_5"/>
    <xsl:text>*#xA;</xsl:text>   
    note: in real coding replace * with &
    </xsl:for-each>
    </Content>
      </ns1:Mail>
      </xsl:template>
      </xsl:stylesheet>
    Kind regards,
    Praveen

    Hi,
    I think <xsl:text>#xa;</xsl:text> should do the trick, but depending on which OS (ux or win), the "new line" chars sequence is different (win would require a CRLF like <xsl:text>#xd;*#xa;</xsl:text>)
    Chris
    -> &
    Edited by: Christophe PFERTZEL on Apr 14, 2010 2:16 PM

  • Tab And New Line in XML data

    I have a formatted text which I store as a text node. By default the new line char's are converted into white spaces. I read elsewhere on this forum, that we should use the charecter entity reference equivalent &#A; for new line. I did not understand this idea clearly, so I tried this out:
    In my formatted string, I replaced all instances of '\n' with '&#A;'. I create my text node as follows:
    script.replaceAll("\n","&#A;");
    scriptElement = document.createTextNode(script);
    As expected when the XML is written the &#A10; is further encoded into "&#A10". And when I read back my XML from the parser, I get my string back with all the "&#A10;". I again need to do a replace all to get the new line charecters back.
    My question is : Is there any other standard solution to this problem or the bottom line is to replace the new line and tabs with "MUMBOJUMBO" or a standard charecter entity ref and look for the same while reading back.
    Is there anyway I could tell my XMLwriter to convert '\n' into "&#A;" and get back '\n' when I parse the XML?

    by default, all white spaces collapse: http://www.w3.org/TR/xsl/slice7.html#white-space-collapse
    you can use xml:space="preserve" in your XML elements (tags) or
    you can use <fo:block white-space-collapse="false" linefeed-treatment="preserve"> in XSL if you use XSL to format the XML.

  • A new line in java

    How to insert a new line char(s) into a java String? a single '\n' seems not the best solution.

    whadda wrong with /n...???well it's \n ;-) but other then that
    there is nothing wrong wiht it, if it is used properly.
    \n represents a specific ascii code (13 I think but I'm not sure)
    if you want to put that ascii code into your string it is the correct thing to use.
    but what is considert the end of a line depends on the OS some use
    \n some use \r\n (or was it the other way round?). So if you want to put a end of line in a String (or file or whatever use the system property as described in a previouse post
    regards
    Spieler

  • New Line Character in SQL Query

    Dear All,
    I am wondering if some one tell me how to insert new line character in the SQL Query Output for example I need out put in the following format. Every line on new line.
    The total count is:
    Registration: 1111
    Fees paid: 2222
    Admission Done: 3333
    Total:4000
    Many thanks

    Hi
    SQL> select
      2  'The total count is:
      3  Registration: 1111
      4  Fees paid: 2222
      5  Admission Done: 3333
      6  Total:4000
      7  ' dummy_txt from dual
      8  /
    DUMMY_TXT
    The total count is:
    Registration: 1111
    Fees paid: 2222
    Admission Done: 3333
    Total:4000
    SQL>
    SQL> select 'a'||chr(10)||'b' from dual;
    'A'
    a
    b
    SQL> T

  • Cannot Add new line using BI IP query

    Hi All,
    We have created a planning application (BI IP Query) and used it in VC 7.1 model using BI Query Wizard service. Now we are able to customize existing rows ( existing rows are using flat file upload)... we can able to change the existing record values and save it.
    But we are not able to add new line... its going to dump... We are able to add new line using WAD with same query but not in VC 7.1
    This issue is same as below 2 threads...
    Re: How to create new records through a VC form in an input-ready query??
    Re: Cannot add new records through VC form when consuming IP write back query?
    Thanks,
    PradeeP

    Its working now... SAP has given the fix (patch) for this issue when we deployed it, everything is working fine... I think they will release this fix (patch)soon...
    Raise an Sap OSS message for solution

  • How to remove new line character from query output?

    Hi,
    How to remove new line character from query output?
    have tried select replace(column_name, CHR(10), ' ') from table_name.
    Edited by: GreenHorn on Sep 11, 2008 12:53 AM

    Please consider, that windows uses a sequence of chr13||chr(10) Unix uses only one character chr(10).
    The new line character(s) may be OS-dependent.
    You could consider both with:
    replace(replace(column_name, CHR(13)||CHR(10), ' '),CHR(10),' ')
    Hartmut
    Edited by: hartmutm on 11.09.2008 01:32

  • Can we achieve new line character(\n) using xpath function??

    All,
    I want to use new line character for some text formating. Does xpath function supports new line character? If so, which function to use? If not, what is the alternative I can use to achive this?
    Rgds
    sen

    Hi Shine SS,
    Had same requirement and your solution worked.
    Thanks.

  • New Line Character of  pl/sql in Insert Query

    Iam in need of New Line Character in pl/sql.
    In forms at the time of concatenation of two text box values into a single text box and a new line inbetween the two text box values and it is inserted into the database.
    (ie) Name :
    (We need a new line Character in between Name and Designation)
    Designation :
    Thankyou

    Hi,
    You could use something like this.
    insert into <table>....... :name||chr(10)||:designation;
    HTH.
    Regards,
    Arun

  • How do you restrict new line in input field or delete last char. in as3?

    Sorry, Noobie here!
    I have a text input box. If the enter key is pressed, a new line begins; thus making the previous line invisible unless the backspace key is pressed.
    So, if i type "1" into the input box, then hit eneter the number "1" becomes invisible, unless I hit back.
    Now, I still need the enter key because i have an event listener that calls a function once it is pressed, but i still need that "1" to be visible.
    So, I need one of either:
    To be able to restrict the input text field from creating a new line (making max line allowed= 1)
    or
    To delete the last character entered in the input text if the enter key is pressed.
    Both of these should have the same result, however I don't know how to do both.
    If anyone can help, i'd be very grateful!

    This worked! Thanks so much!

  • XPath query error - xml extension in schema

    Hi,
    I am getting following error when i try to assign values to input xml payload before
    invoke process.
    "{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.
    <selectionFailure>
    <part name="summary" >
    <summary>XPath query string returns multiple nodes. According to BPEL4WS spec 1.1 section 14.3, The assign activity part and query /child::parameter/child::param1 should not return multipe nodes. Please check the BPEL source at line number "40" and verify the part and xpath query /child::parameter/child::param1. </summary>
    </part>
    </selectionFailure>
    The generated XPath resolves to a single node only (tested using XMLSpy). The only reason i can think of is that the xml schema in wsdl is extending a base xml type to a new type.
    It works fine if the extending xml type is merged with it's base type, and used as one single complex type.
    ------------------WSDL START
    <?xml version="1.0" encoding="UTF-8"?>
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://justdoit.ws.sunflower2.pageone.com" targetNamespace="http://justdoit.ws.sunflower2.pageone.com">
         <types>
              <xs:schema targetNamespace="http://justdoit.ws.sunflower2.pageone.com">
                   <xs:complexType abstract="true" name="BaseObject">
                        <xs:sequence>
                             <xs:element name="param1" nillable="true" type="xs:string"/>
                             <xs:element name="param2" nillable="true" type="xs:string"/>
                        </xs:sequence>
                   </xs:complexType>
                   <xs:complexType name="FooBar">
                        <xs:complexContent>
                             <xs:extension base="tns:BaseObject">
                                  <xs:sequence>
                                       <xs:element name="param3" nillable="true" type="xs:string"/>
                                       <xs:element name="param4" nillable="true" type="xs:string"/>
                                       <xs:element name="param5" nillable="true" type="xs:string"/>
                                       <xs:element name="param6" nillable="true" type="xs:string"/>
                                  </xs:sequence>
                             </xs:extension>
                        </xs:complexContent>
                   </xs:complexType>
              </xs:schema>
         </types>
         <message name="justDoItRequest">
              <part name="parameter" type="tns:FooBar"/>
         </message>
         <message name="justDoItResponse">
              <part name="parameter" type="tns:FooBar"/>
         </message>
         <portType name="justDoItPort">
              <operation name="justDoIt">
                   <input message="tns:justDoItRequest"/>
                   <output message="tns:justDoItResponse"/>
              </operation>
         </portType>
         <binding name="justDoItBinding" type="tns:justDoItPort">
              <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
              <operation name="justDoIt">
                   <soap:operation soapAction="tns:justDoIt"/>
                   <input>
                        <soap:body use="literal"/>
                   </input>
                   <output>
                        <soap:body use="literal"/>
                   </output>
              </operation>
         </binding>
         <service name="justDoItService">
              <port name="NewPort" binding="tns:justDoItBinding">
                   <soap:address location="http://127.0.0.1:8080/axis/services/justDoIt"/>
              </port>
         </service>
    </definitions>
    ------------------WSDL END
    ------------------BPEL START
              <assign name="assign-1">
                   <copy>
                        <from variable="input" part="payload" query="/tns:justDoItRequest/tns:input1"></from>
                        <to variable="req" part="parameter" query="/parameter/param1"/>
                   </copy>
              </assign>
              <invoke name="invoke-1" partnerLink="justDoIt" portType="tns:justDoItPort" operation="justDoIt" inputVariable="req" outputVariable="res"/>
    ------------------BPEL END
    reg,
    Amitoj.

    I am also having the xml extension issue and since we are dealing with large WSDL files (exceed 40,000 lines) it would be ridiculous to move all extension classes to the base type (parent class). Has this bugged been looked at and when can it be resolved since it seems to be a major issue in JDeveloper.
    Chris

  • Master detail new line error

    Hi all, Can anyone help me with this problem?
    I have created a master detail table but have had problems with adding new detail lines.
    The detail region contains an advanced table with an addTableRow bean set in the footer. I wish to navigate to a new page when the ‘add new row’ button is selected so I have set the ‘insert rows automatically’ property to false. I have been able to capture the event in my controller and call the new page and then access the application module, however I do not seem to be able to set a property in the new child line from an attribute in the parent line.
    //in my AM I have called…
    public void CreateLine()
    //get child vo that is to have line added
    DoiLinesVOImpl vo = (DoiLinesVOImpl) getDoiLinesVO1();
    if (!vo.isExecuted()) vo.executeQuery();
    //find parent vo to determine which questionId the line relates to
    OAViewObject hvo = (OAViewObject)findViewObject("DoiDecQuestionsVO1");
    OARow hRow = (OARow)hvo.getCurrentRow();
    Number sid = (Number) hRow.getAttribute("QuestionId ");
    System.out.println ( " qid= " + qid );
    if ( vo != null)
    vo.setMaxFetchSize(0);
    Row vRow = vo.createRow();
    vo.insertRow(vRow);
    vRow.setAttribute("QuestionId",qid);
    vRow.setNewRowState(Row.STATUS_INITIALIZED);
    Initially the page was running, however it was only ever showing the id for the first line, regardless of which child table I was select add new line on. Now the new page errors and when I click on exception details the page does not show any error details
    Can anyone see anything wrong with the code in the AM or have any suggestions as to what else may be wrong. Is it actually possible to do what I am trying to do? My aim is to have a table of questions and then a table region under the detail region of each question. Either no lines, one line or multiple lines can be added under each questions details. The questions may have slightly different required fields so I would like to navigate to a new page and then back to the main page when save is selected.
    Any insights into what I am doing wrong or how I might achive my requirement would be very much appreciated.
    Mike.

    Ok, I have now got the page to stop erroring.
    I have created a new VO instance of the child EO in the application module and used the new vo in the seperate create page attributes, however when I query the current row against the parent vo I am still getting the value from the first line, not the selected parent line.
    mike.

Maybe you are looking for

  • HT3775 Is the Codec listed adjacent to the file format the Codec used with that file format?

    Is the Codec listed adjacent to the file format the Codec used with that file format?

  • Can't call WCF Data Service from within a WCF Service

    I am trying to query my WCF Data Service from within a WCF Service and I receive a error 404.  However, when I query the data service from my application, it works just fine.  The WCF Service will work just fine if I comment out the Data Service quer

  • Pass fail decision for DMM readings

    Hi, Hope you will excuse a newby's ignorance. I have LabVIEW V8.2 with no add on's and a PXI chassis. I want to measure the resistance between about 100 points for pin 1 to pin 2 , then pin 3 etc to pin 100, then pin 2 to pin3, ...pin 100. The only w

  • Cteate 2 Dynamic drop down list

    Hi all i want to create 2 dynamic drop down list using struts and hibernate i want the first one to display countries name then if i select a country name the second drop down list will automatic display the country cities . i'm using database here a

  • Runtime jar loading

    Is there an easy(ish) way to take advantage of extension technology purely at runtime? I'm developing an application (so (almost) no security issues) which needs to load classes and other resources from jar files which are unknown until runtime (e.g.