L. Quastana
L. Quastana

Reputation: 1336

JAVA Regex with XML

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.

Upvotes: 0

Views: 201

Answers (2)

L. Quastana
L. Quastana

Reputation: 1336

?? = DocumentBuilderFactory.newInstance().newDocumentBuilder()
         .parse( new InputSource( new StringReader( XMLLine ) ) )
         .getElementsByTagName("TtlIntrBkSttlmAmt")
         .item(0).getAttributes().getNamedItem("Ccy").getNodeValue();

Upvotes: 1

user1334319
user1334319

Reputation:

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.

Upvotes: 1

Related Questions