0

i have this String and i need to get the attribut Ccy to TtlIntrBkSttlmAmt with a regex.

Can you help me to have the best pattern ?

<?xml version = "1.0" encoding = "UTF-8"?>
<Document xmlns = "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
    <FIToFICstmrCdtTrf>
        <GrpHdr>
            <MsgId>XXXXXXXXXXX</MsgId>
            <CreDtTm>2013-07-23T16:30:14</CreDtTm>
            <NbOfTxs>0</NbOfTxs>
            <TtlIntrBkSttlmAmt Ccy = "EUR">0000.00</TtlIntrBkSttlmAmt>
            <IntrBkSttlmDt>2013-07-24</IntrBkSttlmDt>
            <SttlmInf>
                <SttlmMtd>CLRG</SttlmMtd>
                <SttlmAcct>
                    <Id>
                        <IBAN>XXXXXXXXXXXXXXXX</IBAN>
                    </Id>
                </SttlmAcct>
                <ClrSys>
                    <Prtry>XXXXX</Prtry>
                </ClrSys>
            </SttlmInf>
        </GrpHdr>

Thank you.

7
  • 5
    Why Regex? What's wrong with XPath? Commented Jul 24, 2013 at 8:38
  • 2
    Why dont you use XML Parsing library? Commented Jul 24, 2013 at 8:39
  • 1
    Because a work with an ETL and a can't use a Dom parser ! Commented Jul 24, 2013 at 8:39
  • 7
    You don't parse (x|h)tml with regex. Commented Jul 24, 2013 at 8:40
  • 5
    Define ETL and tell us exactly why it prevents you from using an XML parser. I have a hard time understanding why those are incompatible. Commented Jul 24, 2013 at 8:43

2 Answers 2

1

I wouldn't use a Regex, use an XML parser instead. Anyway...

(?!= <TtlIntrBkSttlmAmt)Ccy = "[A-Z]+"

Should do the trick. Edit the [A-Z] group to meet your specific needs.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your solution but finally i have create a static fonction which convert my String to Document XML and get my attribut
1
?? = DocumentBuilderFactory.newInstance().newDocumentBuilder()
         .parse( new InputSource( new StringReader( XMLLine ) ) )
         .getElementsByTagName("TtlIntrBkSttlmAmt")
         .item(0).getAttributes().getNamedItem("Ccy").getNodeValue();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.