{"record":{"id":"326f65c9c39ecdf4","repo":"apache/hadoop","slug":"you-must-put-edits-at-the-top-of-the-xml-file-g","errorCode":null,"errorMessage":"you must put <EDITS> at the top of the XML file! Got tag {} instead","messagePattern":"you must put <EDITS> at the top of the XML file! Got tag (.+?) instead","errorType":"validation","errorClass":"InvalidXmlException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java","lineNumber":138,"sourceCode":"    opCode = null;\n    cbuf = new StringBuilder();\n    nextTxId = -1;\n  }\n  \n  @Override\n  public void endDocument() {\n    if (state != ParseState.EXPECT_END) {\n      throw new InvalidXmlException(\"expecting </EDITS>\");\n    }\n  }\n  \n  @Override\n  public void startElement (String uri, String name,\n      String qName, Attributes atts) {\n    switch (state) {\n    case EXPECT_EDITS_TAG:\n      if (!name.equals(\"EDITS\")) {\n        throw new InvalidXmlException(\"you must put \" +\n            \"<EDITS> at the top of the XML file! \" +\n            \"Got tag \" + name + \" instead\");\n      }\n      state = ParseState.EXPECT_VERSION;\n      break;\n    case EXPECT_VERSION:\n      if (!name.equals(\"EDITS_VERSION\")) {\n        throw new InvalidXmlException(\"you must put \" +\n            \"<EDITS_VERSION> at the top of the XML file! \" +\n            \"Got tag \" + name + \" instead\");\n      }\n      break;\n    case EXPECT_RECORD:\n      if (!name.equals(\"RECORD\")) {\n        throw new InvalidXmlException(\"expected a <RECORD> tag\");\n      }\n      state = ParseState.EXPECT_OPCODE;\n      break;","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L120-L156","documentation":"The XML edits state machine starts in ParseState.EXPECT_EDITS_TAG, so the very first start-element SAX event must be <EDITS>. Any other root element (or a namespaced/wrapped root the loader does not recognize) throws InvalidXmlException telling you to put <EDITS> at the top. This is a structural guard, not a namespace check: the comparison is on the local name only.","triggerScenarios":"Feeding oev an XML file whose root element is not EDITS — e.g. an fsimage XML, a generic configuration XML, or an edits document wrapped inside another element.","commonSituations":"Pointing -i at the wrong file after renaming outputs; merging XMLs under a synthetic root; confusing offlineImageViewer (oiv) output with offlineEditsViewer (oev) input.","solutions":["Make <EDITS> the outermost element of the file passed to oev's XML loader.","Confirm you are giving oev an edits XML (produced by 'hdfs oev -p xml'), not an fsimage XML.","Regenerate the file from the original binary edits log instead of editing."],"exampleFix":"<!-- before -->\n<edits-wrapper><EDITS>...</EDITS></edits-wrapper>\n\n<!-- after -->\n<EDITS>...</EDITS>","handlingStrategy":"validation","validationCode":"// Root-element check with a streaming reader\nXMLInputFactory f = XMLInputFactory.newFactory();\ntry (XMLStreamReader r = f.createXMLStreamReader(\n        new FileInputStream(file))) {\n  r.next();\n  if (!\"EDITS\".equals(r.getLocalName())) {\n    throw new IOException(\"Root element must be <EDITS>, found <\"\n        + r.getLocalName() + \">\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  if (e.getMessage().contains(\"top of the XML file\")) {\n    throw new IOException(\"Wrong document structure: \" + e.getMessage()\n        + \". Use an edits XML produced by 'hdfs oev -p xml'.\", e);\n  }\n  throw e;\n}","preventionTips":["Label generated files clearly (edits.xml vs fsimage.xml) so oev and oiv inputs never get swapped.","Automate XML production from binary edits rather than assembling documents by hand."],"tags":["hadoop","hdfs","offline-edits-viewer","xml","parsing"],"backgroundTag":"malformed-xml-document","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}