Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions formats/xml/src/main/java/io/cloudevents/xml/XMLDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,8 @@ private CloudEventData processData(Element data) throws CloudEventRWException {

Element eventData = findFirstElement(data);

Element newRoot = newDoc.createElementNS(eventData.getNamespaceURI(), eventData.getLocalName());
newDoc.appendChild(newRoot);

// Copy the children...
NodeList nodesToCopy = eventData.getChildNodes();

for (int i = 0; i < nodesToCopy.getLength(); i++) {
Node n = nodesToCopy.item(i);

if (n.getNodeType() == Node.ELEMENT_NODE) {
Node newNode = newDoc.importNode(n, true);
newRoot.appendChild(newNode);
}
}
// Copy the element with its attributes and all of its children
newDoc.appendChild(newDoc.importNode(eventData, true));

newDoc.normalizeDocument();
retVal = XMLCloudEventData.wrap(newDoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ public static Stream<Arguments> deserializeArgs() {
Arguments.of("v1/xml_data.xml"),
Arguments.of("v1/xml_data_with_ns1.xml"),
Arguments.of("v1/xml_data_with_ns2.xml"),
Arguments.of("v1/xml_data_with_ns3.xml")
Arguments.of("v1/xml_data_with_ns3.xml"),
Arguments.of("v1/xml_data_with_attrs.xml"),
Arguments.of("v1/xml_data_with_text.xml")
);
}

Expand Down
16 changes: 16 additions & 0 deletions formats/xml/src/test/resources/v1/xml_data_with_attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<event xmlns="http://cloudevents.io/xmlformat/V1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
specversion="1.0">
<id>1</id>
<source>http://localhost/source</source>
<type>mock.test</type>
<datacontenttype>application/xml</datacontenttype>
<data xsi:type="xs:any">
<!-- Attributes and text content on the data root element -->
<Order xmlns="http://someauthority.example/" id="42" status="shipped">
<Item sku="A1">Widget</Item>
</Order>
</data>
</event>
14 changes: 14 additions & 0 deletions formats/xml/src/test/resources/v1/xml_data_with_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<event xmlns="http://cloudevents.io/xmlformat/V1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
specversion="1.0">
<id>1</id>
<source>http://localhost/source</source>
<type>mock.test</type>
<datacontenttype>application/xml</datacontenttype>
<data xsi:type="xs:any">
<!-- Data root element with text content only -->
<greeting xmlns="">Hello World</greeting>
</data>
</event>
Loading