This is a shortened version with altered data for security reasons of the xml im receiving, and I'm trying to check if the field 'workemail' is empty and if not I'm going to create one:
i have tried using the absolute and relative path for it and using getLength to see if it even gives me anything but I only get:
java.net.MalformedURLException: no protocol
public void checkEmployeeEmail(String input) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringBuilder xmlStringBuilder = new StringBuilder();
ByteArrayInputStream inputStream = new ByteArrayInputStream(
xmlStringBuilder.toString().getBytes("UTF-8"));
Document doc = builder.parse(input);
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "//*/PersonalInfo_GetAll_AllEmployeesByCompanyResult/PersonalInfoItem/EmailWork";
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
System.out.println(nodeList.getLength());
}
}
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PersonalInfo_GetAll_AllEmployeesByCompanyResponse
xmlns="https://api.nmbrs.nl/soap/v3/EmployeeService">
<PersonalInfo_GetAll_AllEmployeesByCompanyResult>
<PersonalInfoItem>
<EmployeeId>1</EmployeeId>
<EmployeePersonalInfos>
<PersonalInfo_V2>
<Id>1</Id>
<DisplayName>person 1</DisplayName>
<EmployeeNumber>7</EmployeeNumber>
<FirstName>firstname1</FirstName>
<Initials>T.T</Initials>
<LastName>firstname</LastName>
<Nickname>lastname</Nickname>
<Gender>female</Gender>
<NationalityCode>1</NationalityCode>
<PlaceOfBirth>amsterdam</PlaceOfBirth>
<CountryOfBirthISOCode>NL</CountryOfBirthISOCode>
<IdentificationNumber>NV2H6DD52</IdentificationNumber>
<IdentificationType>10</IdentificationType>
<TelephoneMobilePrivate>0000000</TelephoneMobilePrivate>
<TelephoneMobileWork>000000</TelephoneMobileWork>
<EmailPrivate>person@gmail.com</EmailPrivate>
<EmailWork>tblabla@workemail.com</EmailWork>
<BurgerlijkeStaat>2</BurgerlijkeStaat>
<Naamstelling>1</Naamstelling>
<Birthday>1994-04-14T00:00:00</Birthday>
<CreationDate>2020-07-30T08:54:41.04</CreationDate>
<StartPeriod>7</StartPeriod>
<StartYear>2020</StartYear>
</PersonalInfo_V2>
<PersonalInfo_V2>
<Id>98351</Id>
<DisplayName>person2</DisplayName>
<EmployeeNumber>7</EmployeeNumber>
<LastName>lastname2</LastName>
<Nickname>firstname2</Nickname>
<Gender>undefined</Gender>
<NationalityCode>0</NationalityCode>
<IdentificationType>0</IdentificationType>
<EmailWork>person2@workemail.com</EmailWork>
<BurgerlijkeStaat>0</BurgerlijkeStaat>
<Naamstelling>0</Naamstelling>
<Birthday>0001-01-01T00:00:00</Birthday>
<CreationDate>2020-06-17T12:52:21.273</CreationDate>
<StartPeriod>1</StartPeriod>
<StartYear>1</StartYear>
</PersonalInfo_V2>
</EmployeePersonalInfos>
</PersonalInfoItem>
</EmployeePersonalInfos>
</PersonalInfoItem>
</PersonalInfo_GetAll_AllEmployeesByCompanyResult>
</PersonalInfo_GetAll_AllEmployeesByCompanyResponse>
</soap:Body>
</soap:Envelope>