Parse XML formatted String

Hi All,
   I have a string field that is formatted in XML format. What I want to be able to do is pull a specific element from the xml formatted string.
Example string:
<customer><name>john</name><id>25636</id></customer>
I want to retreive just the id number of 25636 from this string.
I would I go about accomplishing this?
Thank you in advance,

I fixed it on my own.
Here' s my answer for others that may need it:
if(instr({field.xmlstring},'</id>')  - instr({field.xmlstring},'<id>') = 7)then
   mid(totext({field.xmlstring}),instr({field.xmlstring},'<id>')+4,3)
else if(instr({field.xmlstring},'</id>')  - instr({field.xmlstring},'<id>') = 8)then
   mid(totext({field.xmlstring}),instr({field.xmlstring},'<id>')+4,4)
else if(instr({field.xmlstring},'</id>')  - instr({field.xmlstring},'<id>') = 9)then
   mid(totext({field.xmlstring}),instr({field.xmlstring},'<id>')+4,5)
I use the conditions to cover all possible lengths of the id number.

Similar Messages

  • How to Parse XML into String in BPEL?

    Hi,
    Can anyone tell me, how can I parse XML into String?
    I am taking input from File Adapter, File adapter is reading that XML.
    Then in assign activity i am using XPath expression(built functions) using XMLParser(),doTranslateToNative() etc.. many functions I have tried but XML is not getting parsed into String Variable.
    Please help me asap.
    Thanks
    Shikha

    Thanks a lot Eric.
    I am trying this, oraext:get-content-as-string('receiveInput_Read_InputVariable','body','/ns3:orders')
    but getting this error
    <bpelFault><faultType>0</faultType><subLanguageExecutionFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>XPath expression failed to execute. An error occurs while processing the XPath expression; the expression is oraext:get-content-as-string('receiveInput_Read_InputVariable','body','/ns3:orders'). The XPath expression failed to execute; the reason was: internal xpath error. Check the detailed root cause described in the exception message text and verify that the XPath query is correct. </summary></part><part name="code"><code>XPathExecutionError</code></part></subLanguageExecutionFault></bpelFault>

  • Xerces - Parse XML from String

    I am trying to parse an xml string using Xerces.
    I have the following code:
    String xml = <segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0"  pointIndex="0" meters="122" seconds="11"  distance="0.1 mi"  time="11 secs">Head  <b>southwest</b> from <b>B Ave NE</b>
    </segment>
    <segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment>
    <segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment>
    <segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment>
    <segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment>
    <segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment>;
    XMLReader reader = new SAXParser();
    reader.setContentHandler(new Handler());
    reader.parse(xml);I am getting the followoing error:
    org.xml.sax.SAXParseException: File "<segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0" pointIndex="0" meters="122" seconds="11" distance="0.1 mi" time="11 secs">Head  <b>southwest</b> from <b>B Ave NE</b></segment><segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment><segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment><segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment><segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment><segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment></segments>" not found.
         at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1219)
         at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:501)
         at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:314)
         at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1097)
         at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1139)
         at com.shiftyeyes.xmlTest.main(xmlTest.java:34)
    Exception in thread "main" anyone know how I can fix this? Thanks!!

    reader.parse(new InputSource(new StringReader(xml)));

  • SaxParser error  parsing xml encoded string

    I'm trying to parse an XML string with Java's SaxParser. The program
    fails at the end of an element or at the beginning of a new element.
    Is my XML string okay?
    <?xml version="1.0" encoding="utf-8"
    ?><DTYPE>OVL</DTYPE><DTYPE>IMG</DTYPE>. . .
    If fails after </DTYPE> and before the next <DTYPE>
    The Sax Parser works fine on files.
    Here is the code I use to send the string to the parser :
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    InputStream is = new ByteArrayInputStream(stringToParse.getBytes());
    saxParser.parse( is, handler );
    Here is the error message I get :
    org.xml.sax.SAXParseException: Inadmissible sign at the document end<
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3376)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3370)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:673)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
    at
    org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:143)
    at EchoSaxParser.parse(EchoSaxParser.java:51)
    at StringParser.parse(StringParser.java:23)
    at Servant.stringparse(Servant.java:30)
    at TEST._TestImplBase._invoke(_TestImplBase.java:43)
    at
    com.sun.corba.se.internal.corba.ServerDelegate.dispatch(ServerDelegate.java�:353)
    at com.sun.corba.se.internal.iiop.ORB.process(ORB.java:280)
    at
    com.sun.corba.se.internal.iiop.RequestProcessor.process(RequestProcessor.ja�va:81)
    at
    com.sun.corba.se.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.ja�va:106)
    Any help would be greatly appreciated!
    Thank you!

    <?xml version="1.0" encoding="utf-8" ?><DTYPE>IMG</DTYPE><DTYPE>REF</DTYPE>Above is a short XML string that causes the problem.
    It's all one line.
    I also tried adding System.getProperty("line.separator") add the
    end of each tag so I get :
    <?xml version="1.0" encoding="utf-8" ?>
    <DTYPE>IMG</DTYPE>
    <DTYPE>REF</DTYPE>But same error. It still crashes after the first <DTYPE></DTYPE> tag.
    Any help greatly appreciated!

  • Parse xml as string, not file

    I have to parse an xml file i get as a string,
    what;s the best way to parse it w/o converting to file.
    then i need just to get the elements , what's the most simple way
    and which parser to use.
    my task woudl be aggregation.
    say i have several elements. and i would like to aggregate all the chidlren in one vector/ array. (ie alles value zusammen)
    <elem1>
    <value> data</value
    <value> data</value
    <value> data</value
    <value> data</value
    </elem1>
    <elem2>
    <value> data</value
    <value> data</value
    <value> data</value
    </elem2>

    tha's great is i want a listener, whic requires lots' of extra code
    ok i can convert string to input stream in a similar manner
    Document document = parser.parse(my inputsream) ,
    and then iterate through the tags :
    document.getElementsByTagName(tag);
    is this the best /fast way terms of coding ?
    /my task is to place all the tags' values in a record set/

  • Parse XML from string.

    I have writen simple fuction which have one parameter of String type. In this parameter i am sending an XML string. Is there anyone who knows how to parse this XML-String ?
    Thanks.

    parse(new StringReader(theString));

  • How to remove extra spaces in a xml formatted string

    Hi,
    I am trying to remove extra spaces between the xml tags. For
    example, if a string is something like
    ' <header 1> <header 2> test </header 2> </header1>'
    I want to get rid of the spaces only between the closing tag of header 1 and opening tag of header 2 and closing tag of header 2 and opening tag of header 1, in short ,I want to remove the extra spaces between the tags if there are no other characters between them. I do not want the remove the spaces between closing tag header 2 and opening tag of header ,as there is occurence of other characters.
    I am aware that this can be done by looping through the string and using instr to identify the characters '<' and '>', but I would like to use it as a last resort only.
    Can anyone suggest me a better way of doing it in a single go by manipulating the data?
    Any help is really appreciated.
    Regards,
    Anil.

    You can use the replace function. If you only expect one extra space, then:
    scott@ORA92> select replace ('<header 1> <header 2> test </header 2> </header1>',
    2      '><', '><')
    3 from dual
    4 /
    REPLACE('<HEADER1><HEADER2>TEST</HEADER2></HEADER
    <header 1> <header 2> test </header 2> </header1>
    If you expect more extra spaces, then you will need to wrap another replace function around it for each space, for example the following will eliminate up to three spaces:
    scott@ORA92> select replace (replace (replace ('<header 1> <header 2> test </header 2> </header1>',
    2      '>     <', '><'), '>     <', '><'), '> <', '><')
    3 from dual
    4 /
    REPLACE(REPLACE(REPLACE('<HEADER1><HEADER2>TEST
    <header 1><header 2> test </header 2></header1>

  • XML Parsing From A String (Not a File)

    Hi all,
    I've been looking throughout this forum and still can't find a total answer to my question. I was wondering if it is possible to do the following:
    I want to pass in a string of XML code to a java stored procedure; the XML string looking like the following (for example):
    <Table-Name="PersonalInfo">
    <row>
    <First-Name>Bob</First-Name>
    <Last-Name>Smith</Last-Name>
    <Age>55</Age>
    </row>
    </Table-Name>
    We don't want to be passing in an XML file; we want to pass in the actual string of XML code that would be in the file.
    Is it possible to put into the DOM format (like every example I've seen so far) by parsing an XML formatted string? If so, how would I go about doing that?
    Thanks in advance!
    Jadie

    <Table-Name="PersonalInfo">
    <row>
    <First-Name>Bob</First-Name>
    <Last-Name>Smith</Last-Name>
    <Age>55</Age>
    </row>
    </Table-Name>This is exactly what JAXB is for! :)
    With JAXB unmarshalling against an XSD file can be applied to any InputStream, etc.
    Take a look at JAXB, and you'll find it'll be just what you're looking for. :)
    In fact, here's a short segment of the XSD you'd write for the above:
    <xsd:complexType name="PersonalInfo">
    <xsd:sequence>
    <xsd:element name="row" type="PersonalInfoRow" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="PersonalInfoRow">
    <xsd:sequence>
    <xsd:element name="First-Name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
    <xsd:element name="Last-Name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
    <xsd:element name="Age" type="xsd:int" minOccurs="1" maxOccurs="1"/>
    <xsd:sequence>
    </xsd:complexType>
    Also, perhaps redesign your XML a little, since each table will be different, simply use its name as the tags...i.e. <PersonalInfo></PersonalInfo> and change the <row> to <PersonalInfo> since <row> is pretty generic and will probably occur many times in other places.
    Hope this helps you along your way. :)
    -G

  • Parsing String in XML format

    Hello,
    What is the proper way to parse XML String instead of a XML file?.

    Use new InputSource(new StringReader(s)).
    Good luck.

  • How to parse XML string fetched from the database

    i want to parse the XML string which is fetched from the oracle database.
    i have inserted the string in xml format in the database. The type of the field in which it is inserted is varchart2.
    I am successfully getting it using jdbc, storing it in a String.
    Now it is appended with xml version 1.0 and string is ready for parsing.
    Now i am making following programming.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = Builder.parse(xmlString);
    Element root = doc.getDocumentElement();
    NodeList node = root.getElementsByTagName("product");
    But i am getting IOException at the statement
    Document doc = Builder.parse(xmlString);
    there fore i request u to kindly help me in solving this error.
    -regards
    pujan

    DocumentBuilder does not have a method parse with xml string as aparameter. The string should be a xml document uri.
    Convert xml string to StringReader.
    parse(new InputSource(new StringReader(xmlString)));

  • Parsing formatted String to Int

    How can I parse formatted string to Integer ?
    I have a formated string like this $900,000 and I need to convert it to 900000 so I could do calculations with it.
    I tried something like this
    NumberFormat nf = NumberFormat.getIntegerInstance(request.getLocale());
    ttlMargin=nf.parse(screenVal);I got this exception
    "java.lang.NumberFormatException: For input string: "$1,050,000""

    I am working on the JSP file that provides
    margins,sales etc. I am reading this data off the
    screen where it is beeing displayed according to the
    accounting practices.
    That's why I get it as a formatted string and why I
    am trying covert that string to the numberScreen-scraping is a problematic, bad design. It sounds like what you really want is to call a web service which returns its results as data that a program can understand (XML, for example), not HTML (which is meant more for humans to read). I know, you probably can't change the design at this point... just food for thought. In the meantime, you'll probably have to manually parse those strings yourself by stripping out the '$' and ',' characters and then use parseInt on the result.

  • Swift Adapter for bea8.1 Error in parsing swift format to xml

    hi All,
    I need your help, how to parse swift format to xml format. Suppose I took one example of swift Message Type, that was MT103
    To convert this message I have tried all of these methods:
    wlai.swiftMT103EventMT103Event.SWIFTMT103Document.Factory.parse(File)
    wlai.swiftMT103EventMT103Event.SWIFTMT103Document.Factory.parse(String)
    wlai.swiftMT103ServiceMT103Request.SWIFTMT103Document.Factory.parse(File)
    wlai.swiftMT103ServiceMT103Request.SWIFTMT103Document.Factory.parse(String)
    But I still found the error
    com.bea.xml.XmlException : Unexpected element :CDATA
    while these methods were executed.
    so anyone can help me how to transform swift format to xml format..?..
    The final purpose of my transformation is transforming swift format to mainframe format..
    so anyone has the clue how to do that..?
    Thanks,
    Juned

    Hello
    I've solved the problem.
    In the stack.xml file are multiples software-components with the same name, here "SERVERCORE".
    I had 3 entries, two with patch-level 0 and one with patch-level 1.
    I've deleted the two entries with patch-level 0 and then it works.
    Regards Christian

  • How can I convert IDoc in XML format w/DTD into a string?

    I want to send by e-mail outbound IDoc in XML format with its document type definition (DTD).
    I want to be able to get the same output result into a string than the XML file IDoc port type with DTD activated.  I have created a FM (based on SAP "OWN_FUNCTION") assigned to an IDoc port of type ABAP-PI that executes the following processing steps:
    1-Extract outbound IDoc information to get the sender & recipient mail addresses (EDP13 / EDIPHONE tables).
    2-Convert & Transform IDoc data into XML string using FM IDX_IDOC_TO_XML.
    3-Prepare and send e-mail with XML attachement using FM SO_NEW_DOCUMENT_ATT_SEND_API1.
    I cand generate the e-mail with the XML file attachement but FM IDX_IDOC_TO_XML does not convert the IDoc with proper formating and DTD.
    What should I use to accomplish the IDoc conversion to XML w/DTD into a string?
    Should I use XSLT tools ?
    How does that work?
    Thank you
    Carl

    muks wrote:
    Use decimal string to number
    Specifically, you can define a constant with a different datatype on the input on the lower left if you need a different datatype (e.g. U8, I64, DBL, etc) Are all your values integers or do you also need to scan fractional numbers? In this case, you should use "fract/exp string to number" instead.
    LabVIEW Champion . Do more with less code and in less time .

  • Converting String To XML Format and send as attachment

    Hi
    My requirement is to convert String into XML Format and that XML File i have to send as an attachment
    can any one one give solution for this Problem.
    Thank you
    Venkatesh.K

    hi,
    i m filling the itab first and converting to xml
    itab contaning these data
    GS_PERSON-CUST_ID   = '3'.
    GS_PERSON-FIRSTNAME = 'Bill'.
    GS_PERSON-LASTNAME  = 'Gates'.
    APPEND GS_PERSON TO GT_PERSON.
    GS_PERSON-CUST_ID   = '4'.
    GS_PERSON-FIRSTNAME = 'Frodo'.
    GS_PERSON-LASTNAME  = 'Baggins'.
    APPEND GS_PERSON TO GT_PERSON.
    after conversion data is coming like that
    #<?xml version="1.0" encoding="utf-16"?>
    <CUSTOMERS>
      <item>
        <customer_id>0003</customer_id>
        <first_name>Bill</first_name>
        <last_name>Gates</last_name>
      </item>
      <item>
        <customer_id>0004</customer_id>
        <first_name>Frodo</first_name>
        <last_name>Baggins</last_name>
      </item>
    </CUSTOMERS>
    but errors are  1) # is coming at the first
                            2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
    can anybody plz solve it.
    regards,
    viki

  • Converting string to XML format

    Hi All,
    I have a requirement to convert string to xml format and download it. Atpresent, I have a string which is a collection of xml tags. I want to convert this string to xml format like <VALUE004>20387899.437</VALUE004>
    <VALUE005>20387899.437</VALUE005>
    <VALUE006>20387899.437</VALUE006>
    Is there any function module for this.

    Chk this thread.
    Re: Regd: File Conversion to XML format

Maybe you are looking for

  • HOW TO GET THE VALUE OF A NODE IN XMLDOC?

    i have an xml doc like this: <FUSIONHUB> <INFO> <COMPANY_ID>A001</COMPANY_ID> </INFO> </FUSIONHUB> HOW TO RETRIEVE THE VALUE A001? I HAVE USED NODE.getNodevalue() method but it returned null instead of A001. can anybody please answer ? waitng for rep

  • Tree control - How to get the full path of selected Item in tree control

    I am Flex newbie. When the user clicks the particular item in the tree control I just wanted to get it name along with it's full parent. Here is my XML var dirXML:XML=<root basename="/home/tcegrid"> <Directories> <Dir Name=".autosave" /> <Dir Name=".

  • Have lost all my mail folders on Thunderbird, how do i get them back?

    I lost my second search window for Thunderbird Mail so went to VIEW, TOOLBARS and selected all three options - MAIL, STATUS and QUICK FILTER. I got my search window back that enables me to search my emails for messages from a specific person. However

  • Help home button suddenly not working properly after io5 update!!

    having finally got ios 5 after multiple attempts now a few days in the home button has decided to have a mid of its own? in app...take 5-10 presses to exit app?? home screen double tap to show appswitcher sometimes just doesnt happen was all fine til

  • SRM-MDM Catalog - Transfer Product masters

    Hi Guys, I am using SRM 5 and SRM-MDM 2.0. I have uploaded using MDMGX all the product groups, currencies, and UOMs successfully. Now I have set up XI and SRM for transferring Product masters, suppliers and contracts. When I run BBP_CCM_TRANSFER, I a