diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java index a2f172933161..b1418366218b 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java @@ -279,7 +279,7 @@ private static List getRecordFieldsForXMLElement(Element xmlElement, boole if (xmlNode.getNodeType() == org.w3c.dom.Node.ATTRIBUTE_NODE) { if ((xmlNode.getPrefix() == null && XMLNS_PREFIX.equals(xmlNode.getLocalName())) || (XMLNS_PREFIX.equals(xmlNode.getPrefix()) && - xmlNode.getLocalName().equals(xmlElement.getPrefix()))) { + xmlNode.getLocalName().equals(xmlElement.getPrefix())) && withNameSpace) { String prefix = null; if (xmlElement.getPrefix() != null && xmlElement.getPrefix().equals(xmlNode.getLocalName())) { prefix = xmlNode.getLocalName(); diff --git a/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java b/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java index c7b2c2da2de3..1a713220b1fa 100644 --- a/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java +++ b/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java @@ -159,6 +159,11 @@ public class XMLToRecordConverterTests { private final Path sample23Bal = RES_DIR.resolve(BAL_DIR) .resolve("sample_23.bal"); + private final Path sample24XML = RES_DIR.resolve(XML_DIR) + .resolve("sample_24.xml"); + private final Path sample24Bal = RES_DIR.resolve(BAL_DIR) + .resolve("sample_24.bal"); + private static final String XMLToRecordServiceEP = "xmlToRecord/convert"; @@ -378,6 +383,15 @@ public void testXMLWithConflictingElementAndAttributeNames() throws IOException Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); } + @Test(description = "testXMLWithoutNamespaces") + public void testXMLWithoutNamespaces() throws IOException { + String xmlFileContent = Files.readString(sample24XML); + String generatedCodeBlock = XMLToRecordConverter.convertXMLToRecord(xmlFileContent, false, false, false, + null, false).getCodeBlock().replaceAll("\\s+", ""); + String expectedCodeBlock = Files.readString(sample24Bal).replaceAll("\\s+", ""); + Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); + } + @Test(description = "testXMLToRecordService") public void testXMLToRecordService() throws IOException, ExecutionException, InterruptedException { Endpoint serviceEndpoint = TestUtil.initializeLanguageSever(); diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_24.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_24.bal new file mode 100644 index 000000000000..358fe421e7ae --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_24.bal @@ -0,0 +1,12 @@ +type Book_BookItem record { + string[] authorName; +}; + +type Book_BookList record { + Book_BookItem bookItem; +}; + +@xmldata:Name {value: "library"} +type Example_Library record { + Book_BookList bookList; +}; diff --git a/misc/xml-to-record-converter/src/test/resources/xml/sample_24.xml b/misc/xml-to-record-converter/src/test/resources/xml/sample_24.xml new file mode 100644 index 000000000000..3ed7bf752ab7 --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/xml/sample_24.xml @@ -0,0 +1,8 @@ + + + + Value 1 + Value 2 + + +