I have the following code to find type of required node.
private void handleDemote(CalendarCustomization calendar)
{
String name = calendar.getName();
Node node = (Node)reader.read("/APIBusinessObjects/Calendar[Name='" + name + "']/Type", XPathConstants.NODE);
...}
public Object read(String expression, QName returnType)
{
try
{
XPathExpression xPathExpression = xPath.compile(expression);
return xPathExpression.evaluate(xmlDocument, returnType);
}
catch (XPathExpressionException ex)
{
ex.printStackTrace();
return null;
}
}
The xml which I am trying to parse has te following content
<Calendar>
<BaseCalendarObjectId xsi:nil="true" />
<HoursPerDay>8</HoursPerDay>
<HoursPerMonth>173.3</HoursPerMonth>
<HoursPerWeek>40</HoursPerWeek>
<HoursPerYear>2080</HoursPerYear>
<IsDefault>0</IsDefault>
<IsPersonal>0</IsPersonal>
<Name>test'sCal</Name>
The getName function is returning me the test'sCal.So name =test'sCal . The problem is with the apostrophe as the expression contains single extra quote. it shortens the name causing the expression to become wrong. Please suggest .