How to convert a delimited string to XML?

Hi there,
Please help me to convert a pipe delimited string into XML, e.g.
string -------SubName:abc|SuvValue:123|
required XML:
<ROWS>
<ROW>
<SubName>abc</SubName>
<SubValue>123</SubValue>
</ROW>
</ROWS>
or
string -------abc|123|
required XML:
<ROWS>
<ROW>
<SubName>abc</SubName>
<SubValue>123</SubValue>
</ROW>
</ROWS>
-----i am trying to first parse the string into a table type and then using the DBMS_XMLGen.getXML function but unable to get values from table type...
any prompt response is highly appriciated...
Regards, Hassan

Hi Hassan,
If your version supports it (ie 10gR2 and upwards), you can use XQuery to directly parse the string and generate the XML :
SQL> SELECT XMLQuery(
  2   '<ROWS>
  3    <ROW> {
  4     for $i in ora:tokenize($str,"\|")
  5     return
  6      if ($i) then element {substring-before($i,":")} {substring-after($i,":")}
  7      else ()
  8   } </ROW>
  9   </ROWS>'
10   passing sys_xmlgen('SubName:abc|SubValue:123|') as "str"
11   returning content
12  ).getClobVal()
13  FROM dual;
XMLQUERY('<ROWS><ROW>{FOR$IINO
<ROWS><ROW><SubName>abc</SubName><SubValue>123</SubValue></ROW></ROWS>
Each element is built based on its name from the input string.

Similar Messages

  • Converting Delimited string to XML message

    Hi,
    We are trying to convert pipe delimited string into a xml schema using a XSD and BPEL funtion. Consider a scenario in which message has 5 fields with last as 2 optional fields. So the incoming string message can be like "1|2|3" or "1|2|3|4|5". In this case how the XSD should look like, since for each field we have to give "terminatedby" option in the XSD. So the issue is coming for element 3 where the delimiter can be "|" or "eol" (end of line). How to specify that ? Is there any option to use like "optionally terminated by?"
    Any help will be appreciated.
    Thanks,
    Ramesh
    Edited by: rameshchandra85 on 2 Aug, 2010 10:00 AM

    Hi Ramesh,
    You can use below XSD for input file of kind
    1|2|3
    1|2|3|4|5
    1|2|3|4
    1|2|3|4|5|6
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
                targetNamespace="http://TargetNamespace.com/InboundService"
                xmlns:tns="http://TargetNamespace.com/InboundService"
                elementFormDefault="qualified"
                attributeFormDefault="unqualified" nxsd:encoding="ASCII" nxsd:stream="chars" nxsd:version="NXSD">
      <xsd:element name="Root-Element">
        <xsd:complexType>
          <xsd:choice minOccurs="1" maxOccurs="unbounded" nxsd:choiceCondition="terminated" nxsd:terminatedBy="|">
            <xsd:element name="RECORD1" nxsd:conditionValue="1">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;">
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="RECORD2" nxsd:conditionValue="2">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C5" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;">
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="RECORD3" nxsd:conditionValue="3">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;">
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="RECORD4" nxsd:conditionValue="4">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C5" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy="&quot;">
                  </xsd:element>
                  <xsd:element name="C6" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;">
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    <!--NXSDWIZ:D:\DBIN\ReadFile.txt:-->
    <!--USE-HEADER:false:-->But in your case if you are getting 5 elements instead of 3 elements in some other file....Use the same and maipulate the last element afterwards.
    I think we can not have an element definition for two scenarios.
    Update you if i get any..
    Regards
    PavanKumar.M

  • HOW TO CONVERT PDF FILE IN TO XML FILE?

    HOW TO CONVERT PDF FILE IN TO XML FILE

    No Office programs can open a pdf and edit the contents so you will have to get a different app to convert teh pdf into xls format. There are plenty to be found on the web.
    Rod Gill
    The one and only Project VBA Book
    Rod Gill Project Management

  • How to Convert Oracle Apps Report into XML Publisher

    Hi
    How to Convert Oracle Apps Report into XML Publisher?
    Thanks

    In Brief :
    Re: XML Publisher
    In Details :
    http://www.oracle.com/technology/products/xml-publisher/docs/XMLEBSRep.pdf

  • How to convert Binary to String?

    Hi,
    How to convert Binary to String? Thank!

    Never ceases to amaze me how many people cannot
    accept any form of criticism whatsoever. How dothey
    get through the normal day? Do they pick fightswith
    everyone who says anything to them they don'tlike?
    Was this for me????Who are you calling a psycho??

  • How to convert HL7 file into an XML

    Hi All,
    I am new to HL7,can any one tell how to convert HL7 file into an XML.Give sample demo or related links.
    My sample HL7 file is as follows how can I convert.
    FHS|^~\&||Tax ID123^Lab Name123^L|||201110191435||HL7.txt||1234567|123||
    PID|seqno|123||john^chambers^^Dr^Dr|2456 california ave^San jose^CA^85254|19601212|M
    FHS|^~\&||Tax ID123^Lab Name123^L|||File Creaqted Date|File Security|FileName||File HeaderComment||Facility|FileCreatedDateTime|File Security|File Name|File Header Comment|FileControlId|Reference File Control ID|
    PID|seqno|patientId||LastName^FirstName^MiddleName^Title^Degree|Street^City^State^zip|patientDOB|gender
    <Report>
    <FileHeader>
    <FileSendingApplication> </FileSendingApplication>
    <TaxID>Tax ID123</TaxID>
    <LabName>Lab Name123</LabName>
    <FileSendngFacilityType>L</FileSendngFacilityType>
    <FileReceivingApplication></FileReceivingApplication>
    <FileReceivingFacility></FileReceivingFacility>
    <FileCreatedDateTime>201110191435</FileCreatedDateTime>
    <FileSecurity></FileSecurity>
    <FileName>HL7.txt</FileName>
    <FileHeaderComment></FileHeaderComment>
    <FileControlId>1234567</FileControlId>
    <ReferenceFileControlID></ReferenceFileControlID>
    <FileHeader>
    <Patient>
    <seqno> </seqno>
    <patientId>Tax ID123</patientId>
    <LastName>Lab Name123</LastName>
    <FirstName>L</FirstName>
    <MiddleName></MiddleName>
    <Title> </Title>
    <Degree></Degree>
    <Street></Street>
    <City></City>
    <State>HL7.txt</State>
    <Zip></Zip>
    <patientDOB>1234567</patientDOB>
    <gender></gender>
    <Patient>
    </Report>
    Thanks
    Mani

    Hi Prabu,
    With input as in single line I'm able to get the the output but with the multiple lines of input,error was occured.Any suggestions.
    Error while translating. Translation exception. Error occured while translating content from file C:\temp\sampleHL7.txt Please make sure that the file content conforms to the schema. Make necessary changes to the file content or the schema.
    The payload details for this rejected message can be retrieved.          Show payload...
    Thanks
    Mani

  • How to convert byte into string

    can any tell me how to convert byte into string
    when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
    package str;
    import java.io.*;
    public class Testfile {
    public static void main(String rags[])
    byte b[]=new byte[100];
    try{
    FileInputStream file=new FileInputStream("abc.txt");
    file.read(b,0,50);
    catch(Exception e)
         System.out.println("Exception is:"+e);
    System.out.println(b);
    String str=new String(b);
    System.out.println(str);
    }

    Namrata.Kakkar wrote:
    errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
    If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] .

  • How to split a delimited string into an array...

    I have a delimited string coming in to a stored procedure (SP) for vb.net that needs to be parsed/converted into multi-dimensional arrays. The reason I am using delimited string because I do not know how to pass arrays to oracle SP from vb.net using ODP or MPO (Microsoft's Provider for Oracle).
    My delimited string looks something like this: "level1_1|level2_1:level3_1;level3_2|level2_2:level3_1;level3_2~Level1_2|level2_2:level3_1"
    So, its going to be 3d array. I would greatly appreciate if anyone could help me solving this puzzle. Any examples would be a great help.
    Thanks for everything in advance,
    Vincent

    Hi Andrew,
    I appreciate your response. Currently I use "Microsoft provider for Oracle" to connect to Oracle Database because when I started with my application there wasn't ODP (Oracle Data Provider for .Net) available. So, I used Microsoft provider and still using it.
    I know how to use arrays in .Net but the problem is I can not find the Oracle Type to pass the array to Oralce Stored Procedure using this provider.
    It would be very helpful if someone shows me the syntax for both to receive from oracle and transport to Oracle. I haven't tried using ODP yet. May be now its the time to see how it works.
    And of course, your link was very helpful but I am already doing that (which is very slow for multi-dimentional array). So, I thought there might be a built in function in oracle which does that. Because most of the programming languages does have built in function for this conversion. for example: Split() in vb, java, javascript etc.
    Anyway, if anyone finds any clues as to how to pass milti-dimentional arrays from .Net (microsoft) to oracle stored procedure please, please let me know how to do that.
    -Vincent

  • How to convert number to string in java

    hi how can i convert number to string in java
    something like
    public void Discription(Number ownerName){
    String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PM

    Yet another way of doing it is: ownerName.toString().
    If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them.

  • How do you pass a string into xml

    How do we pass a string to be parsed as xml
    something like
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    oc = docBuilder.parse (String s);
    Thanks
    Arnold

    String xmlString = "<?xml version=\"1.0\"?>\n<myelement myattribute=\"myvalue\"/>\n";
    InputSource inputSource = new InputSource(new StringReader(xmlString));
    Document document = builder.parse(inputSource);

  • How to convert LongRaw to String when querying using DB Adapter?

    Hi All,
    How do we use a DB Adapter to query on LONG Raw data? Is there a way to implicitly convert data to a string before returning the resultSet?
    JDev: 11.1.1.4
    Regards.

    Hi,
    LONG RAW data will be retrieved as base64binary, you can use and Embed Java to convert it back to string.
    How to convert String to base64Binary in BPEL process
    Or you can use doTranslateFromNative oracle extension function, you will need a NXSD template to use it.
    http://docs.oracle.com/cd/E15523_01/integration.1111/e10224/bp_appx_functs.htm#CJACABGA
    Cheers,
    Vlad

  • How to Convert JTextArea to String

    How would i convert JTextArea to string?

    elaborate, whats RTFAPI? I searched for it and got
    nothing.Since I'm not quite sure if you are being sarcastic, that translates to "read the f*cking application programmer interface". :)

  • How to convert CSV/Text files to XML format

    Hi,
    I am trying to convert a .csv/.txt(Flat) file(s) to XML format. How can i achive this?
    Ex: I want to convert this text file to XML.
    Book#      first name                                last name                               ID#                 ID1#      F#
    B99          FRISBY                                  NASIER                                  LUCJ A         A 3127      1    
    B131         HAWKINS                              MICHAEL                               LUCJ A         A 3129       2    
    B313         KING                                     JOSHUA                                 CUCJ I         I-DORM      10   
    B307         GRAVES                               KIMBERLY                              NUCJ F         F-DORM     24-FL
    R469         HEATH                                  DARRELL                                SUCJ A         A 3132       1    
    R212         PEREZ                                  DARRELL                                SUCJ A         A 3133       2    
    R62          COFFEY                                GREGORY                               NUCJ HC      H C 3112    3FLOOR
    R215         BLACKWELL                          DEREK                                   LUCJ OOW     W 01       1     Could anyone please suggest me if we have any open source java api to acheive this?
    Thanks,
    Srikanth.

    Have a look at [http://servingxml.sourceforge.net/|http://servingxml.sourceforge.net/] or [http://www.talend.com/|http://www.talend.com/]

  • How to convert integer to string?

    for example :
    int num = 1;
    String num_str;
    how to convert the value of num variable to string .

    have u ever checked the documentation of WTK
    one method called valueOf
    will help u
    alpesh

  • How to convert Oracle Collection(Objects) to XML dynamically?

    Dear members,
    As a requirement I need to pass the collection of values(typically a object or a table type) to a procedure and generate a XML file on the fly basing on these collection values.I am not sure how to do it.Can anyone please guide me on that?
    Thanks

    Hi,
    depending on how often/how complex the programming job is:
    --- complex Xml structure, lots of changes: Have a look at [Oracle XML DB Developers Guide|http://download-west.oracle.com/docs/cd/B28359_01/appdev.111/b28369/toc.htm], chapter 3: Using Oracle XML DB
    --- simple:
    Here's a quick sample for generating Xml from SQL collection types. Works (at least) >= 10g.
    create type xxp_foo_type as object (
    a number
    instantiable
    create type xxp_foo_tab as table of xxp_foo_type
    declare
    v_table xxp_foo_tab := xxp_foo_tab();
    v_xml xmltype;
    begin
    v_table.extend(2);
    v_table(1) := xxp_foo_type( 1 );
    v_table(2) := xxp_foo_type( 2 );
    select xmlelement( "MyXml",
    xmlagg(
    xmlelement( "SomeValue", t.a )
    into v_xml
    from table( v_table ) t
    dbms_output.put_line( v_xml.getStringVal() );
    end;

Maybe you are looking for

  • Is Screen Sharing with multiple users possible?

    I am trying to discuss some documents with multiple users. It works very well with just two users sharing the screen of one of them, so I was wondering if there was a way to have a third user participating. If iChat does not allow this, does anyone k

  • Error message from itunes setup assistant

    When I open iTunes to sync my iPod-Touch, I get an error message regarding the registry and suggest that I re-install iTunes. Message: Warning. The registry settings used by the iTunes drivers for importing and burning CD's and DVD's are missing. Thi

  • Connect iPhone to Projector?

    Guys, Can any one let me know of how to use the iphone to connect to a projector so that we can simply demonstrate the application on a large screen? (just as shown in Keynote!!) Earlier response is appreciated. Thanks, Goldeni

  • How to find .pld files version in Oracle apps

    Hi, How to find .pld file version in Oracle apps using unix command or any other way. Regards

  • FixedLengthTooShortHandling problem

    Hi All, I have configured a file to file scenario with File Content Conversion. I have a structure with 2 fields. The first field has fixed length of 2 bytes but the second field is variable. It is not a CSV file. I have used the following configurat