Resolving xml entities only in a string

Hi!
Is there any function in any API that can resolve XML entities like & to &, > to > and so on that can handle the input as a string?
/Tec

If you mean, is there any Java method to convert "&lt;" to < and so on, no, there isn't. However if you use standard XML parsers then you don't have to worry about that issue because they take care of it for you. If you're writing your own parser then you have to write the unescaping code yourself.

Similar Messages

  • Encoding Individual Strings with XML entities to replace "&", " ", etc.

    We use templates to create XML files. The tags are in the templates and just the values get substituted in. Sometimes the variable value contains an ampersand or other XML-banned character.
    1) Is there a simple method in the Java or Xerces class libraries that takes a string and returns one with the suspect characters replaced by XML entities?
    2) Sometimes, though rarely (I have no control over this!) the variables arrive with the forbidden characters already replaced by entities. Is there a method which will tell me if the string already contains entities, or at least is already a valid XML string? Otherwise I'm afraid the ampersand in an already-converted entity name will itself be converted to another entity.
    Thanks!

    I'm not aware of any built-in mechanism for doing that kind of escaping short of a full XML generator. Here's a lightweight solution that replaces ampersands only if they're not part of an XML entity. Just grab a copy of Elliott Hughes' Rewriter and implement it like this: public class Test
      /* Rewriter can be found here:
       * http://elliotth.blogspot.com/2004/07/java-implementation-of-rubys-gsub.html
      public static void main(String... args) throws Exception
        Rewriter xmlEscaper = new Rewriter("[<>'\"]|&(?!(?:lt|gt|apos|quot|amp);)")
          public String replacement()
            char ch = group(0).charAt(0);
            switch (ch)
              case '<'  : return "&#38;lt;";
              case '>'  : return "&#38;gt;";
              case '\'' : return "&#38;apos;";
              case '"'  : return "&#38quot;";
              case '&'  : return "&#38amp;";
              default :
                throw new IllegalStateException("this can't happen");
        String str = "this & that & the <other&#38gt;";
        System.out.println(xmlEscaper.rewrite(str));
    }

  • XML entities in xs:base64Binary

    Hi there,
    this is my first Post, and i hope i am at the right place in this forum.
    I am integrating a third party application, that provides WSDL files for generating web services. An internal Web Service is creating an XML which is than encoded via base64 an sent as a SOAP message to the application.
    So the SOAP message contains an element (type xsd:base64Binary) in wich the base64 content is transported. The problem is, that in this base64 string, there are xml entities &amp;#xA; instead of the allowed base64 whitespace characters.
    Can anyone give me a hint, if these character entities can be supressed?
    Best
    Thomas

    Hi,
    Sorry, but i think i cant do search and replace here.
    @David: the SOAP message containing the base64Binary element is sent from SAP to the application. It is created by a consumer proxy we generated from the WSDL files provided by the third party application (namely StreamServe) . The application cant handle the character entities &amp;#xA; the base64 string contains.
    We also regenerated the proxy class, but there ist still a mapping from the xml schema type xsd:base64Binary to ABAP RAWSTRING.
    This error (or these character entities) occur, since we upgraded to EHP1, so i think there might be the cause for this behaviour.
    Best
    Thomas

  • XSU error oracle.xml.sql.OracleXMLSQLException: Conversion to String failed

    Appication Server: 10g, Database: Oracle 9i and Oracle 10g
    I have a table 'sw_icd2' in the database that has one column of XMLType.
    The code below, attempts to query this table as 'select * from sw_icd2' and display the result. I was able to execute this query in sqlplus.
    But when I run a program using XSU in JDeveloper:
    OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from sw_icd2");
    XMLDocument domDoc = (XMLDocument)qry.getXMLDOM();
    domDoc.print(System.out);
    StringWriter s = new StringWriter(10000);
    domDoc.print(new PrintWriter(s));
    System.out.println(s.toString());
    qry.close();
    I get the following Error:
    "oracle.xml.sql.OracleXMLSQLException: Conversion to String failed"
    Any ideas on how I can resolve this issue? Your help would be appreciated.
    Thanks!

    Okay, it looks like the problem has something to do with the TIMESTAMP data type in tables.
    oracle.xml.sql.query.OracleXMLQuery can't seem to handle tables with the TIMESTAMP data type.
    this code ran fine on my machine :
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    import java.lang.*;
    import java.sql.*;
    public class testXMLSQL {
         public static void main(String[] args) {
    try {
    // Create the connection
    System.out.println("before getConnection ");
    Connection conn = getConnection("scott","tiger");
    System.out.println("after getConnection ");
    // Create the query class
    OracleXMLQuery qry = new OracleXMLQuery(conn, "SELECT * FROM EMP");
    System.out.println("after OracleXMLQuery object created ");
    // Get the XML string
    String str = qry.getXMLString();
    // Print the XML output
    System.out.println("The XML output is:\n"+str);
    // Always close the query to get rid of any resources..
    qry.close();
    } catch(SQLException e) {
    System.out.println(e.toString());
    // Get the connection given the user name and password.!
    private static Connection getConnection(String username,
    String password)
    throws SQLException
    // register the JDBC driver..
    DriverManager.registerDriver(new
    oracle.jdbc.driver.OracleDriver());
    // Create the connection using the OCI8 driver
    Connection conn =
    DriverManager.getConnection(
    "jdbc:oracle:thin:@<server_name>:1521:<sid>",
    username,password);
    return conn;
    Then I created another table :
    create table emp_test as select * from emp;
    added a timestamp to it :
    alter table emp_test add (time timestamp(6));
    and filled it with timestamp information :
    update emp_test set time = timestamp'2005-09-22 09:26:50.124';
    ran the same code but changed the SQL to :
    "SELECT * FROM EMP_TEST"
    and got the error message :
    The XML output is:
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Conversion to String failed</ERROR>
    looks like bug in OracleXMLQuery object??

  • Only LOB or String Storage is supported in Thin XMLType

    Hi,
    XML statment failed on the following message in Sql Developer :Version 4.1.0.18
    "Only LOB or String Storage is supported in Thin XMLType"
    But , is run successfully from sqlplus :
    SQL>  SELECT XMLQuery('declare namespace pd="http://xmlns.tibco.com/bw/process/2003"; (:
      2   $p/pd:ProcessDefinition/pd:group/pd:activity/config' passing XML as "p" returning content)
      3   from canon.bezeq_xml_tab
      4   where document_id='997834';
    XMLQUERY('DECLARENAMESPACEPD="HTTP://XMLNS.TIBCO.COM/BW/PROCESS/2003";(::)$P/PD:PROCESSDEFINITION/PD
    <config>
      <faultName/>
    </config>
    <config>
      <faultName/>
    </config>
    <config>
      <
    Please advise
    Thanks

    Hi Jeff ,
    Thanks for your help.
    Oracle database is 11.2.0.3 on linux Ent Redhat 4.8
    The oracle client is 12.1
    Tools --> Preferences --> Database --> Advanced --> ClientType --> "ORACLE HOME" --> path to oracle client 12c TNS_NAMES on my local machine.
    Running test return the following message : "Oracle Client Test Results terminated "
    Statment still fail with the same error message.
    Kindly advise ,
    Thanks

  • How to parse whole xml elements into a java String

    hello everybody,
    I am trying to parse whole xml into a string for example
    my xml file is as below:
    <root>
        <element>
           <data id="1">1</data>
        </element>
        <element>
           <data id="2">2</data>
        </element>
    </root>
    in java whole data should be transfered as
    String xmlString ="<root><element><data id=\"1\">1</data></element><element><data id=\"2\">2</data></element></root>";or in a simple way can xml be copied into a string? any assistance ...
    thanQ in Advance.
    Han.

    This code is to convert xml document to a string.
                             try {
                                  javax.xml.transform.TransformerFactory tfactory = TransformerFactory.newInstance();
                                  javax.xml.transform.Transformer xform = tfactory.newTransformer();
                                  javax.xml.transform.Source src = new DOMSource(xmlString);
                                  java.io.StringWriter writer = new StringWriter();
                                  StreamResult result = new javax.xml.transform.stream.StreamResult(writer);
                                  xform.transform(src, result);
                                  //System.out.println(writer.toString());          
                             } catch (TransformerConfigurationException e) {
                                  e.printStackTrace();
                             }catch(Exception ex )
                                  ex.printStackTrace();
                             }

  • Include XML payload as URL query string

    Hello Gurus -
    I have a business requirement that I'm hoping you all can help me with:
    Scenario: Send XML message from SAP XI to a third party system via the Receiver Plain HTTP Adapter
    I need to include the actual XML message as a query string in the target URL at the time of posting. The content of the XML message is determined within XI message mapping and will not be known until runtime, so the URL determination will need to be dynamic.
    For example - a target URL with the "xmldata=" query string:
    http://server01/receiver.asp?xmldata=<?xml version="1.0" encoding="UTF-8"?><headertag><tag1><value1></tag1></headertag>
    Does anyone know how to do this - Is there some communication channel configuration and/or programming that would work?
    Thanks to all!
    Chad

    Hi,
    This is very similar to our scenario. By manipulating some of the Plain HTTP Adapter parameters, my colleague was able to post using xmldata. He set content type to text/plain then set the prolog to xmldata=. Let me know if this worked.
    Regards

  • Converting Oracle XML Query Result in Java String by using XSU

    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

    Hmmm.. Pretty basic just look at the example:
    OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
    String xmlString = qry.getXMLString();
    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

  • UTF-8 conversion to XML entities

    I'm looking for a function/method for converting UTF-8 encoded text into XML entities (like & etc.) anyone that can help?
    /Niels

    hi nilesh,
    UTF 8 does not recognise those special characters. You will have to change the encoding to <b>ISO-8859-1</b>.
    For into on how to do this, check this thread,
    Java Mapping Parsing Error
    Regards,
    Bhavesh

  • HFM 11 -Org by Period- is it possible to show active entities only in EPMA?

    Hello all,
    when i change entities in pov in the data grid there is a checkbox to filter / show the active entities only.
    So i searched a same function in EPMA to work with the entity dimension more comfortable but i didn´´t found any.
    Is it even possible to filter / show only active entities in the EPMA dimension library like in the data grids?
    best wishes
    Martin

    The active flag for an entity exists in the data realm of HFM, not the metadata. It may change from period to period, while the metadata attributes of entities are not changing with period, they are set at design-time. EPMA handles the metadata (design-time) aspects of entities, therefore it has nothing to do with the Active flag.

  • Regex: How do I match only when a string is not entirely numeric?

    Hi,
    I'm using java regular expression pattern matching. I want to receive a successful pattern-match ONLY when a string is NOT comprised entirely of numeric digits [0-9].
    So, for example, when pattern-matching on the following 3 strings,
    "abcdef" would return match = true and
    "abc123" would return match = true and
    "123456" would return match = falseI have tried using the regex pattern [^0-9] but this only seems to work for strings that are one character long. The pattern [^0-9]+ didn't work either.
    What I need is the equivalent pattern to [^\d+] (which is an invalid pattern).
    Please note that I have to solve this one using regular expressions, even though it would be trivial to solve using straight java code!
    Any help much appreciated.

    What I need is the equivalent pattern to
    [^\d+] (which is an invalid pattern).Well as its an invalid pattern, how exactly do you expect us to know what you mean by it?!?
    Based on your textual description of what you want, and on the basis that you seem not to want to negate theopposite, how's this (I assume we're talking core Java regex's?):
    myString.matches(".*[^\\d].*");

  • [svn:bz-3.x] 15191: Minor update to the build. xml and only make files write protected with chmod.

    Revision: 15191
    Revision: 15191
    Author:   [email protected]
    Date:     2010-04-01 07:06:21 -0700 (Thu, 01 Apr 2010)
    Log Message:
    Minor update to the build.xml and only make files write protected with chmod.
    Modified Paths:
        blazeds/branches/3.x/modules/sdk/build.xml

    DyNamic I agree that is sounds like you may be facing a network configuration issue.  Please let your network people know that you need access to the following servers and ports to download Adobe applications through the Adobe Application Manager:
    ccmdls.adobe.com:443
    ims-na1.adobelogin.com:443
    na1r.services.adobe.com:443
    prod-rel-ffc-ccm.oobesaas.adobe.com:443
    lm.licenses.adobe.com:443
    In addition for updates to download properly you will also need access to the following servers:
    http://www.adobe.com/:80
    htttp:///swupmf.adobe.com/:80
    http://swupdl.adobe.com/:80
    http://crl.adobe.com/:80

  • XML Error: Only segments are allowed on top level,found non-segment E1EDK03

    Hi,
    I have a problem in my senario of receiving XML files with a Business Connector (4.7), adding some data to certain segments and elements, do some mapping steps and then convert the XML file to SAP IDoc. Then the IDoc should be send to R/3 system via ALE.
    The senario works so far, if I test it with the "Send XML file.." option in the menu "Test" of the Business Connectior itself.
    If I try to send the XML data as string in my browser the following error always occurs:
    $localizedError:
    com.wm.lang.xml.WMDocumentException: Invalid IDocXML document: Only segments are allowed on top level, found non-segment E1EDK03
    $errorType:
    com.wm.util.coder.InvalidDatatypeException
    If I send send a string containing the XML data incl. the data I actually wanted to add in a flow step, it works.
    Can anybody help me?
    Thanks,
    Kai
    Message was edited by: Kai Lerch-Baier

    I had been using MC Internet Explorer until this . Have compared this one to functioning XML viewable with MS Internet explorer. Below is code I am using trying to resolve this problem.
    <?xml version="1.0"?>
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
    <tt:root name="ecrtas"/>
    <tt:template>
    <tt:loop ref="ecrtas">
    <ImportInstructions>
    <ProjectSponsorInstruction>
      <Instruction mode="Add">
       <SponsorName tt:value-ref="SPONME"/>
       <SponsorNumber>
         <IdValue name="Sponsor Number"><tt:value ref="SPONSOR"/></IdValue>
         </SponsorNumber>
        <SponsorType tt:value-ref="SPONTYP"/>
      </Instruction>
    </ProjectSponsorInstruction>
    </ImportInstructions>
    </tt:loop>
    </tt:template>
    </tt:transform>
    Thank you again

  • Escape XML entities when transforming

    Hey,
    I'm transforming an XML file to another XML format. My problem is that in the original XML there are entities like "&copy". These entities get transformed as well which produces problems later on. Is there some way to avoid the entities from being expanded? I have tried to google for an answer without success. The only thing I found was the "setExpandEntityReferences" which doesn't have any effect. Otherwise the transformation works fine, just having problems with the entities.
    Thanks for any help!

    Generally the parser will expand those entities, so the transformer doesn't even know there were any entities in the document. What you're asking for is for the serializer to put entity references back into the output document. (And preferably for the transformer to preserve them through the transformation, too, I suppose.)
    I don't believe there is anything in XSLT that deals with entities at all... actually, looking at the XSLT recommendation there is an unparsed-entity-uri(string) function, but you're asking about parsed entities from the DTD, right?
    In theory the version of the document with the entities replaced by their replacement text should be equivalent to the version with the entity references, no? Is there just an esthetic difference or is there an actual difference in meaning between what you get and what you want to get?

  • Special characters in XML structure when prepared using String

    Hi,
       I am preparing an XML structure using 'String'. I print the prepared XML structure in the server log. Issue is that I am seeing extra characters([[ and ]]) that I am not printing.
    Please let me know how to get rid of those.
    Code Excerpt
            String xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
            String lsb_xmlcon = xmlHeader;
            logger.info("ReqXMLString Process  1  --->" + lsb_xmlcon);
            lsb_xmlcon = lsb_xmlcon +("\n");
            logger.info("ReqXMLString Process  1.1  --->" + lsb_xmlcon);
            lsb_xmlcon = lsb_xmlcon +("<REQUEST>");
            lsb_xmlcon = lsb_xmlcon +("\n");
            logger.info("ReqXMLString Process  1.2  --->" + lsb_xmlcon);
    Log
    ReqXMLString Process  1  ---><?xml version="1.0" encoding="utf-8" ?>
    ReqXMLString Process  1.1  ---><?xml version="1.0" encoding="utf-8" ?>[[
    ReqXMLString Process  1.2  ---><?xml version="1.0" encoding="utf-8" ?>[[
    <REQUEST>
    Thanks,
    Message was edited by: 996913
    This issue is observed only while running the code in server, not from Jdev.
    When we append the additional tags without new line character, "\n", there are no extra characters being added. Also, in other case also. where we used "Marshaller" to prepare the XML, we have seen this issue.
    After we set the below property to false, we got rid of the extra characters.
                            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
    Apparently the insertion of new line when the code runs on server(Weblogic 10.3.6.0) is creating the issue.
    Please let me know if anyone has come across a similar scenario.
    Thanks,

    I am building this XML in a servlet so ,right, DOM does process XML (even though a valid HTML file can be loaded into a DOM object) but if you build XML using DOM then write the XML out using PrintWriter and Transformer objects this will cause the XML to print out in your browser. If you view source on this XML you will see that the DOM object has translated all special characters to there &xxxx; equivalent. For a example: when the string (I know "cool" java) gets loaded into a attribute using the DOM object then wrote back out it looks like (I know &xxx;cool&xxx; java) if you view the source in your browser. This is what it should do, but the DOM object is not change the � to the "&xxxxx;". This servlet is acting as a gateway between a Java API and a windows asp. The asp will call the servlet expecting to get XML back and load it directly into a DOM object. When the windows DOM object gets the xml that I am returning in this servlet is throws a exception "invalid character" because the � was not translated to &xxxx; like the other characters were. According to the book HTML 4 in 24 hours (and other references) the eacute; or #233; are how you say "�" in HTML or XML. How do you say it?

Maybe you are looking for