mirror of
https://github.com/apache/nifi.git
synced 2025-03-02 15:39:12 +00:00
NIFI-9831: XML schema inference fix for XML elements with attributes
This closes #5895. Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
This commit is contained in:
parent
e052cf81ba
commit
3ef2ad9943
@ -116,13 +116,6 @@ public class XmlRecordSource implements RecordSource<XmlNode> {
|
||||
arrayNode.addElement(childNode);
|
||||
childNodes.put(childName, arrayNode);
|
||||
}
|
||||
|
||||
final Iterator<?> childAttributeIterator = childStartElement.getAttributes();
|
||||
while (childAttributeIterator.hasNext()) {
|
||||
final Attribute attribute = (Attribute) childAttributeIterator.next();
|
||||
final String attributeName = attribute.getName().getLocalPart();
|
||||
childNodes.put(attributeName, new XmlTextNode(attributeName, attribute.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,9 @@ public class TestInferXmlSchema {
|
||||
public void testFlatXml() throws IOException {
|
||||
final RecordSchema schema = inferSchema("src/test/resources/xml/person.xml", false);
|
||||
|
||||
assertEquals(7, schema.getFieldCount());
|
||||
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("ID").get().getFieldType());
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("NAME").get().getFieldType());
|
||||
assertSame(RecordFieldType.INT, schema.getDataType("AGE").get().getFieldType());
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("COUNTRY").get().getFieldType());
|
||||
@ -63,6 +66,8 @@ public class TestInferXmlSchema {
|
||||
public void testFieldsFromAllRecordsIncluded() throws IOException {
|
||||
final RecordSchema schema = inferSchema("src/test/resources/xml/people_nested.xml", true);
|
||||
|
||||
assertEquals(8, schema.getFieldCount());
|
||||
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("ID").get().getFieldType());
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("NAME").get().getFieldType());
|
||||
assertSame(RecordFieldType.INT, schema.getDataType("AGE").get().getFieldType());
|
||||
@ -89,6 +94,9 @@ public class TestInferXmlSchema {
|
||||
@Test
|
||||
public void testStringFieldWithAttributes() throws IOException {
|
||||
final RecordSchema schema = inferSchema("src/test/resources/xml/TextNodeWithAttribute.xml", true);
|
||||
|
||||
assertEquals(3, schema.getFieldCount());
|
||||
|
||||
assertSame(RecordFieldType.INT, schema.getDataType("num").get().getFieldType());
|
||||
assertSame(RecordFieldType.STRING, schema.getDataType("name").get().getFieldType());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user