Created 10-04-2021 01:20 AM
I have XML Data like this:
<?xml version="1.0" encoding="UTF-8"?>
<XYZ>
<ID>1</ID>
<Name>abc</Name>
<JKL>
<ID>10</ID>
<Type>A</Type>
</JKL>
<JKL>
<ID>11</ID>
<Type>B</Type>
</JKL>
</XYZ>
<XYZ>
<ID>2</ID>
<Name>def</Name>
<JKL>
<ID>10</ID>
<Type>A</Type>
</JKL>
<JKL>
<ID>11</ID>
<Type>B</Type>
</JKL>
</XYZ>
I want to replace tag of outer ID tag from the nested XML like:
<?xml version="1.0" encoding="UTF-8"?>
<XYZ>
<XYZID>1</XYZID>
<XYZName>abc</XYZName>
<JKL>
<ID>10</ID>
<Type>A</Type>
</JKL>
<JKL>
<ID>11</ID>
<Type>B</Type>
</JKL>
</XYZ>
<XYZ>
<XYZID>2</XYZID>
<XYZName>def</XYZName>
<JKL>
<ID>10</ID>
<Type>A</Type>
</JKL>
<JKL>
<ID>11</ID>
<Type>B</Type>
</JKL>
</XYZ>
I have used replace tag using expression language(regex) but it changes all the names 'ID' in the xml to 'XYZID' but I only want to change the outside tag name
Any suggestion??
Any help in this issue will be greatly appreciated.
Thank You!
Created 10-04-2021 12:03 PM
@CodeLa
You can accomplish this via the ReplaceText processor using a multi line approach to your Java Regular Expression (regex).
Search Value:
Replacement Value:
The downside to this approach is that you need to configure this processor with an Evaluation Mode of "Entire text", Evaluation Mode of "All", and make sure the configured buffer size is large enough to fit the entire text. This in turn means a higher heap memory utilization when this processor is executing against your FlowFile.
If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.
Thank you,
Matt
Created 10-04-2021 10:20 PM
Hi Matt,
Thanks for the reply but its not changing anything in my current scenario can you please help? I have xml file which i split it and then use replacetext and follow your solution but it didn't help
Created 10-05-2021 12:16 PM
@CodeLa
I setup a dataflow using the exact example you shared:
After the ReplaceText, I see the content is now:
Can you share your sample xml file that is not working?
How is your split being done?
Thanks,
Matt
Created 10-05-2021 10:50 PM
Hi Matt,
Thanks for the solution may be the issue is something else. I have multiple same records which is nested inside another header which i've first spitted and then use replacetext.
Created 10-06-2021 06:02 AM
@CodeLa
It is difficult for me to help determine issue in your dataflows without your complete dataflow.
My guess is somewhere in the process of splitting your xml files the structure has change in such a way that the Java regex I provided no longer matches.