-1

I have a problem finding a multiline string: I have this text in the "contractBytes" var:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Records xmlns="http://www.datapump.cig.com">
<Contract phaseId="4" operation="2">
    <General>
        <ContractCode>8848</ContractCode>
        <DateOfSignature>2009-09-08</DateOfSignature>
        <CreditPurpose id="20"/>
        <NegativeStatus id="4"/>
        <ApplicationDate>2009-09-08</ApplicationDate>
        <StartDate>2009-09-08</StartDate>
        <ExpectedEndDate>2011-03-31</ExpectedEndDate>
        <Subjects>
            <Subject roleId="1">
                <Entity>
                    <Individual gender="1">
                        <FirstName>
<Text language="uk-UA">украинский</Text>
                        </FirstName>
                        <Surname>
<Text language="uk-UA">Первый</Text>
                        </Surname>
                        <FathersName>
<Text language="uk-UA">контрагент</Text>
                        </FathersName>
                        <Classification id="1"/>
                        <DateOfBirth>1980-12-06</DateOfBirth>
                        <Residency id="1"/>
                        <Citizenship code="UA"/>
                        <MaritalStatus id="2"/>
                        <Identifications>
<Identification typeId="2">
<Number>2554209876</Number>
</Identification>
<Identification typeId="4">
<Number>ВЦ620997</Number>
<IssueDate>1997-04-01</IssueDate>
<Authority language="uk-UA">Дебальцевский ГОУМВД Украины в Донецкой области</Authority>
</Identification>
<Identification typeId="1">
    <Number>2554209876</Number>
</Identification>
                        </Identifications>
                        <Addresses>
<Address typeId="2">
<Street>
    <Text language="uk-UA">м. Kharkov, вул. Street, буд. 1, кв. 1</Text>
</Street>
</Address>
                        </Addresses>
                    </Individual>
                </Entity>
            </Subject>
        </Subjects>
    </General>
    <Type>
        <Credit paymentPeriodId="9" paymentMethodId="6">
            <CreditLimit currency="USD">7800.0</CreditLimit>
            <Records>
                <Record accountingDate="2011-04-20">
                    <CreditUsage id="3"/>
                    <ResidualAmount currency="USD">7800.0</ResidualAmount>
                    <OverdueAmount currency="USD">0.0</OverdueAmount>
                </Record>
            </Records>
        </Credit>
    </Type>
</Contract>

I'm trying get part using regex:

Pattern p = Pattern.compile("(<Contract)(.)*(Contract>)", Pattern.DOTALL);
Matcher m = p.matcher(contractBytes);
for (;m.find();)
{
    if (m.group(1).contains("<ContractCode>" + contractCode + "</ContractCode>"))
    {
        dealXmlMap.put(Long.parseLong(contractCode), m.group(1));
        break;
    }
} 

But m.find always returns false. What should I do with this pattern to get the text from contractBytes var?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • 1
    You should probably stop trying to parse XML by hand before you [hurt yourself](http://stackoverflow.com/a/1732454/2517719). http://en.wikipedia.org/wiki/Java_API_for_XML_Processing – Floegipoky Oct 15 '14 at 15:02

1 Answers1

1
(<Contract)(.*)(Contract>)

Try this.See demo.(.)* you were capturing just the first character not all.

http://regex101.com/r/dZ1vT6/25

vks
  • 67,027
  • 10
  • 91
  • 124
  • For the love of god don't give bullets to a man staring down the barrel of a gun and complaining that it's not firing – Floegipoky Oct 15 '14 at 15:08
  • @user3734984 it is working.there is some other error in your code.Mya be some java guy can tell you – vks Oct 15 '14 at 15:13
  • @Floegipoky yeah right.But at least he can get the concept :) – vks Oct 15 '14 at 15:14