Created on 11-19-2024 07:38 AM - edited 11-19-2024 07:40 AM
Hello!
Xml file has the following structure:
<root>
<nested1>
<nested2>
<nested1>value</nested1>
</nested2>
</nested1>
</root>
EvaluateXPath processor type_rec property: name(/*/*[1])
And I got the following error:
EvaluateXPath[id=ce4e0c05-169f-387f-520d-77e2e664bacc] Input parsing failed FlowFile[filename=69de5f2c-a887-4042-8734-beca03e3d27b]: org.apache.nifi.xml.processing.ProcessingException: Parsing failed - Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 5; The element type "nested2" must be terminated by the matching end-tag "</nested2>".
As I understand, parser except, at 4 level closed tag </nested1> , because it'v met open tag with the same name at level 2 (<nested1>). But at level 4 file has a new tag with the same name.
I tried to use ReplcaseText processor for replace
<nested2>
<nested1>
tag combination
with new value - for example:
<nested2>
<nested1_new>
So I tried to rename "nested1" at 4 level with "nested1_new" value. But without result - nothing is replaced.
It there are other ways to solve this problem?
Thanks.
Created 11-20-2024 09:03 AM
Hi,
Im unable to replicate the error . Can you provide more details about your flow with the processor configurations. here is what I tried and it worked:
GenerateFlowFile:
EvaluateXPath:
Output flowfile attributes:
Created 11-20-2024 07:08 AM
Also I tried to solve this problem, by using ScriptExecutor with following Groovy:
import org.w3c.dom.Document
import org.w3c.dom.Element
import groovy.xml.XmlSlurper
import groovy.json.JsonBuilder
def xmlContent = '''<root>
<nested1>
<nested2>
<nested2>value</nested2>
</nested2>
</nested1>
</root>'''
def xml = new XmlSlurper().parseText(xmlContent)
def nested2Value = xml.root.nested1.nested2
def json = [
nested2: nested2Value
]
def json2 = [
nested3: nested2
]
def builder = new JsonBuilder(json2)
def xmlOutput = builder.toPrettyString()
I returns:
{
"nested3": [
]
}
It's not, what I expected, because "value" is missed.
Created 11-20-2024 09:03 AM
Hi,
Im unable to replicate the error . Can you provide more details about your flow with the processor configurations. here is what I tried and it worked:
GenerateFlowFile:
EvaluateXPath:
Output flowfile attributes: