{"record":{"id":"ef2ebf10d5e02f65","repo":"pentaho/pentaho-kettle","slug":"xml-does-not-allow-empty-strings-for-element-names","errorCode":null,"errorMessage":"XML does not allow empty strings for element names.","messagePattern":"XML does not allow empty strings for element names\\.","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/xml/core/src/main/java/org/pentaho/di/trans/steps/addxml/AddXML.java","lineNumber":117,"sourceCode":"    Document xmldoc = getDomImplentation().createDocument( null, meta.getRootNode(), null );\n    Element root = xmldoc.getDocumentElement();\n    for ( int i = 0; i < meta.getOutputFields().length; i++ ) {\n      XMLField outputField = meta.getOutputFields()[i];\n      String fieldname = outputField.getFieldName();\n\n      ValueMetaInterface v = getInputRowMeta().getValueMeta( data.fieldIndexes[i] );\n      Object valueData = r[data.fieldIndexes[i]];\n\n      if ( !meta.isOmitNullValues() || !v.isNull( valueData ) ) {\n        String value = formatField( v, valueData, outputField );\n\n        String element = outputField.getElementName();\n        if ( element == null || element.length() == 0 ) {\n          element = fieldname;\n        }\n\n        if ( element == null || element.length() == 0 ) {\n          throw new KettleException( \"XML does not allow empty strings for element names.\" );\n        }\n        if ( outputField.isAttribute() ) {\n          String attributeParentName = outputField.getAttributeParentName();\n\n          Element node;\n\n          if ( attributeParentName == null || attributeParentName.length() == 0 ) {\n            node = root;\n          } else {\n            NodeList nodelist = root.getElementsByTagName( attributeParentName );\n            if ( nodelist.getLength() > 0 ) {\n              node = (Element) nodelist.item( 0 );\n            } else {\n              node = root;\n            }\n          }\n\n          node.setAttribute( element, value );","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/xml/core/src/main/java/org/pentaho/di/trans/steps/addxml/AddXML.java#L99-L135","documentation":"The AddXML step builds an XML document where each selected field becomes an element (or attribute). When the configured element name is empty, the code first falls back to using the field name; if the field name is also null/empty, no valid XML element name exists, so the step throws this KettleException. XML spec forbids empty element names.","triggerScenarios":"processRow encounters an outputField whose XML 'Field to XML' element name is blank AND the source stream field name is also empty — e.g. a field row with no name and no element name configured in the step dialog.","commonSituations":"Step metadata imported from an incomplete XML/repository definition; renamed/deleted upstream fields leaving the field name empty; programmatically built AddXMLMeta with OutputField having null elementName and fieldName.","solutions":["Open the AddXML step dialog and set a valid 'Element name' for every field in the 'Fields to XML' table","Ensure the incoming stream field has a non-empty name so the fallback (element = fieldname) succeeds","Validate the AddXMLMeta outputFields in code before running the transformation","Re-import/re-save the transformation metadata if the field definitions came from a corrupt repository export"],"exampleFix":"// before\nOutputField f = new OutputField(); // elementName=null, fieldName=null\nfields.add(f);\n// after\nOutputField f = new OutputField(\"customer\", \"customer\", false);\nf.setElementName(\"customer\");\nfields.add(f);","handlingStrategy":"validation","validationCode":"for (XMLField f : meta.getOutputFields()) {\n  String el = f.getElementName();\n  if (el == null || el.isEmpty()) {\n    String fb = f.getName();\n    if (fb == null || fb.isEmpty())\n      throw new IllegalArgumentException(\"Field with no element name and no field name in AddXML step\");\n  }\n}","typeGuard":"boolean hasValidElementName(XMLField f) {\n  return (f.getElementName() != null && !f.getElementName().isEmpty())\n      || (f.getName() != null && !f.getName().isEmpty());\n}","tryCatchPattern":"try { step.processRow(); } catch (KettleException ke) {\n  if (\"XML does not allow empty strings for element names.\".equals(ke.getMessage())) {\n    logError(\"AddXML field missing element name: fix step field table\");\n  }\n}","preventionTips":["Always set both a field name and element name in the Fields to XML table","Preview the step in Spoon to catch empty field rows before production","Validate AddXMLMeta programmatically when generating transformations via API"],"tags":["xml","kettle","configuration","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}