| | |
| | if( !xml.isBlank() ) { |
| | - try( final var reader = new StringReader( xml ) ) { |
| | + try( final var reader = new StringReader( declareEntities( xml ) ) ) { |
| | final var input = new InputSource(); |
| | |
 |
| | |
| | return sDocumentBuilder.newDocument(); |
| | + } |
| | + |
| | + /** |
| | + * Fixes issue where entity "nbsp" was referenced, but not declared. |
| | + * |
| | + * @param xml The document text to convert to a DOM. |
| | + * @return The DOM with the "nbsp" entity declared. |
| | + */ |
| | + private static String declareEntities( final String xml ) { |
| | + return xml.startsWith( "<!DOCTYPE" ) |
| | + ? xml |
| | + : """ |
| | + <!DOCTYPE html [ |
| | + <!ENTITY nbsp " "> |
| | + ]> |
| | + """ + xml; |
| | } |
| | |
 |
| | } |
| | |
| | - public static Node evaluate( final String xpath, final Document doc ) throws XPathExpressionException { |
| | + public static Node evaluate( final String xpath, final Document doc ) |
| | + throws XPathExpressionException { |
| | return (Node) XPATH.evaluate( xpath, doc, NODE ); |
| | } |