Skip to content

Commit d4dbea7

Browse files
Remove root element wrapper when parsing XML string
1 parent 1fb4126 commit d4dbea7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public final class TypeConverter {
113113
public static final String ERROR_MESSAGE_UNION_START = "{";
114114
public static final String ERROR_MESSAGE_UNION_END = "}";
115115
public static final String ERROR_MESSAGE_UNION_SEPARATOR = "or";
116+
public static final String XML_START_ELEMENT = "<";
116117

117118
public static Object convertValues(Type targetType, Object inputValue) {
118119
Type inputType = TypeChecker.getType(inputValue);
@@ -973,8 +974,11 @@ public static BDecimal stringToDecimal(String value) throws NumberFormatExceptio
973974
}
974975

975976
public static BXml stringToXml(String value) throws BError {
976-
BXml item = XmlUtils.parse("<root>" + value + "</root>");
977-
return item.children();
977+
String xml = value.trim();
978+
if (!xml.startsWith(XML_START_ELEMENT)) {
979+
return XmlUtils.parse("<root>" + value + "</root>").children();
980+
}
981+
return XmlUtils.parse(xml);
978982
}
979983

980984
public static RegExpValue stringToRegExp(String value) throws BError {

0 commit comments

Comments
 (0)