pentaho/pentaho-kettle · error · KettleXMLException

Error reading information from XML string :

Error message

Error reading information from XML string : 

What it means

loadXMLString wraps any exception (SAXParseException, etc.) from parsing an XML string into KettleXMLException("Error reading information from XML string : " + Const.CR + string), appending the offending XML to the message. This is the general failure path for string-to-DOM conversion.

Solutions

  1. Examine the embedded string in the message around the reported error position; run it through xmllint to find the syntax fault.
  2. Escape XML special characters in dynamically built XML (use XMLHandler.buildCDATA or escapeHtml-style escaping).
  3. Verify the source actually returned XML and not an HTML error page or empty body.
  4. Fix encoding issues by ensuring the string was decoded with the correct charset.

Example fix

// before
String xml = "<root><a>" + userInput + "</a></root>";
Document doc = XMLHandler.loadXMLString(xml);
// after
String safe = "<root><a><![CDATA[" + userInput.replace("]]>", "]]]]><![CDATA[>") + "]]></a></root>";
Document doc = XMLHandler.loadXMLString(safe);
Defensive patterns

Strategy: try-catch

Validate before calling

DocumentBuilderFactory.newInstance().newDocumentBuilder()
  .parse(new InputSource(new StringReader(xml))); // pre-validate

Type guard

boolean isWellFormedXml(String s) {
  try {
    javax.xml.parsers.DocumentBuilderFactory.newInstance()
      .newDocumentBuilder().parse(new org.xml.sax.InputSource(new java.io.StringReader(s)));
    return true;
  } catch (Exception e) { return false; }
}

Try / catch

try {
  doc = XMLHandler.loadXMLString(xml);
} catch (KettleXMLException e) {
  // message embeds the offending string
  log.error("Bad XML: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: XMLHandler.loadXMLString(String) with syntactically invalid XML: unclosed tags, illegal characters, multiple root elements, invalid entities, empty or null-formatted input.

Common situations: Capturing server responses and feeding them to the parser, truncated XML from socket reads, XML containing unescaped '&' or '<', transformation metadata stored as broken XML in a database.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/212866bf8140c234. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/core/xml/XMLHandler.java:797

  public static Document loadXMLString( DocumentBuilder db, String string ) throws KettleXMLException {

    try {
      StringReader stringReader = new java.io.StringReader( string );
      InputSource inputSource = new InputSource( stringReader );

      Document doc;
      try {
        doc = db.parse( inputSource );
      } catch ( IOException ef ) {
        throw new KettleXMLException( "Error parsing XML", ef );
      } finally {
        resetDocumentBuilder( db );
        stringReader.close();
      }

      return doc;
    } catch ( Exception e ) {
      throw new KettleXMLException( "Error reading information from XML string : " + Const.CR + string, e );
    }
  }

  public static DocumentBuilder createDocumentBuilder( boolean namespaceAware, boolean deferNodeExpansion )
    throws KettleXMLException {
    try {
      DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory();
      dbf.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion", deferNodeExpansion );
      dbf.setNamespaceAware( namespaceAware );
      return dbf.newDocumentBuilder();
    } catch ( ParserConfigurationException e ) {
      throw new KettleXMLException( e );
    }
  }

  private static void resetDocumentBuilder( DocumentBuilder db ) {
    // ThreadLocal-cached builders are reused, so reset parser state between invocations.
    try {

View on GitHub (pinned to f3058517a1)