-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NIFI-15378 - Fix formatting for XML Content Viewer #10679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| final String inputXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
| + "<myMessage xmlns=\"http://abc\">\n" | ||
| + " <header>\n" | ||
| + " <timeStamp>20251218145856Z</timeStamp>\n" | ||
| + " </header>\n" | ||
| + "<responsePayload>\n" | ||
| + " <ResponseRecord>\n" | ||
| + " <recordNumber>0</recordNumber>\n" | ||
| + " <recordPayload>\n" | ||
| + " <myId>123456789</myId>\n" | ||
| + " </recordPayload>\n" | ||
| + " </ResponseRecord>\n" | ||
| + "</responsePayload>\n" | ||
| + " \n" | ||
| + " \n" | ||
| + " \n" | ||
| + "</myMessage>\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note, I'm doing it this way instead of using """ to avoid checkstyle errors about trailing whitespaces when we are doing it on purpose for this specific test.
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing this issue @pvillard31.
On initial review, switching from the StreamSource the DOMSource is concerning, because it introduces potential resource consumption issues with reading the entire document into memory. That is the reason for the StreamSource approach.
Using the DocumentBuilderFactory directly, without the wrapper class from nifi-xml-processing is also a concern.
It looks like a different solution is needed that preserves the streaming strategy.
|
It seems like the particular issue relates to XML that is already formatted, thus having the white space text nodes. I haven't looked closely at the client-side rendering, but there might be an opportunity to adjustment on the frontend. In particular, since the Transformer has indenting enabled, perhaps disabling it could work, similar to how the frontend formats JSON. |
|
I'm looking into improving the transformer using an identity xslt transformation to preserve the streaming capability and not hold the whole document in memory. Making some tests right now. |
|
Pushed a commit with a different approach where I'm adding the transformation logic in the xml-processing bundle and I'm using an XSLT identity to remove the whitespaces/empty lines. I had to add an exclude for a spotbug warning. I used an annotation, let me know if you'd rather go with a proper exclude configuration file. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updated approach @pvillard31.
I don't think it is worth the additional complexity of the XSLT just to remove whitespace in this case. The Content Viewer is for presentation, and we definitely should avoid changing the nifi-xml-processing module for this purpose.
|
@pvillard31 Taking a quick look at the frontend configuration for CodeMirror, I'm wondering if the best solution is actually to remove reformatting on the server side and simply allow CodeMirror to handle formatting. |
Actually that may not be an option without an additional library, so something on the server side is probably still needed. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pvillard31, going in the direction of a frontend change looks much more streamlined. It looks like some of the backend changes can be reverted. I'm not sure about keeping the unit test, perhaps a more simplified version may still be useful, but it might be better to remove for now since it only relates to XML.
I will take a closer look at the frontend code changes.
...essing/src/main/java/org/apache/nifi/xml/processing/transform/StandardTransformProvider.java
Outdated
Show resolved
Hide resolved
...ent-viewer/src/main/java/org/apache/nifi/web/controller/StandardContentViewerController.java
Show resolved
Hide resolved
...nt-viewer/src/app/pages/standard-content-viewer/feature/standard-content-viewer.component.ts
Show resolved
Hide resolved
0714919 to
3146369
Compare

Summary
NIFI-15378 - Fix formatting for XML Content Viewer
As a side note:
was introduced in NiFi 2 but was not there in NiFi 1. I'm removing it as I'm not sure why we would want to remove it.
Before change:
After change:
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation