Skip to content

fix(xml): keep attributes and text of the XML data root element - #759

Open
RaphaelFakhri wants to merge 1 commit into
cloudevents:mainfrom
RaphaelFakhri:fix-xml-data-root-content
Open

RaphaelFakhri wants to merge 1 commit into
cloudevents:mainfrom
RaphaelFakhri:fix-xml-data-root-content

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #758

Summary

XMLDeserializer.processData rebuilt the xs:any data root element with createElementNS and copied only its child elements. The attributes and text content of the root element were dropped, so <Order id="42">...</Order> came back as <Order>...</Order>, and <greeting>Hello World</greeting> came back empty.

This change imports the whole root element with Document.importNode(eventData, true), which keeps its namespace, attributes, and all children.

Tests

  • Adds v1/xml_data_with_attrs.xml (root element with attributes) and v1/xml_data_with_text.xml (root element with text only) to the deserialize and roundTrip cases in XMLFormatTest.
  • Without the fix, both new roundTrip cases fail. With the fix, all 73 tests in cloudevents-xml pass.
./mvnw -pl formats/xml test

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XML format drops attributes and text of the data root element

1 participant