In Java, when I attempt to create a new InputSource
and hand it a ByteArrayInputStream
it does not create a CharacterStream nor is encoding set.
XPathExpression compilablePath = xpath.compile("/OutputRoot/Output/AuthPlus/DataMatches/NoAgePri");
String result = compilablePath.evaluate(
new InputSource(new StringReader(xml))
);
if (!"".equals(result)) {
this.noAgePri = Integer.parseInt(result);
}
I'm doing the above, where xml
is a valid XML stored as a String. The XML itself is as below.
<?xml version="1.0" encoding="utf-16"?>
<OutputRoot>
<Output>
<Control>
<Reference>ZX1J49CKQ4</Reference>
</Control>
<AuthPlus>
<ApplicantIdentifier>1</ApplicantIdentifier>
<AuthPlusRef />
<IACA>
<NoPriItem>12</NoPriItem>
<StrtOldPri>199402</StrtOldPri>
<NoSecItem>4</NoSecItem>
<NoSecSrc>1</NoSecSrc>
<StrtOldSec>201608</StrtOldSec>
</IACA>
<AOCA>
<NoPriItem>1</NoPriItem>
<StrtOldPri>200910</StrtOldPri>
<NoSecItem>1</NoSecItem>
<NoSecSrc>1</NoSecSrc>
</AOCA>
<IAPA>
<NoPriItem>0</NoPriItem>
<NoSecItem>0</NoSecItem>
<NoSecSrc>0</NoSecSrc>
</IAPA>
<AOPA>
<NoPriItem>0</NoPriItem>
<NoSecItem>0</NoSecItem>
<NoSecSrc>0</NoSecSrc>
</AOPA>
<DataMatches>
<NoAgePri>10</NoAgePri>
</DataMatches>
<Decision>
<DecCode>AU01</DecCode>
<DecText>The Applicant has been Authenticated to your required 'Level 1'</DecText>
<AuthIndex>80</AuthIndex>
<AuthText>A high level of Authentication has been found for the identity supplied</AuthText>
<IDConfLvl>1</IDConfLvl>
<IDConfText>The identity supplied has been confirmed at the required 'Level 1'</IDConfText>
<HighRiskCount>0</HighRiskCount>
</Decision>
</AuthPlus>
</Output>
</OutputRoot>
The result is that result
is an empty string and thus noAgePir
is not set.
Thanks in advance for any help.
Fixed.
Thanks for all the help - the main issue was with the XPath I was using. For some reason the XML file was not considering Output
a valid tag - only when I did /OutputRoot/child::node()[2]/AuthPlus/DataMatches/NoAgePri
did it work.
Still not sure why but it works at least.