Skip to content
Merged
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
4 changes: 2 additions & 2 deletions module-ballerina-xsd/BalTool.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
id = "xsd"

[[dependency]]
path = "../xsd-cli/build/libs/xsd-cli-1.2.0.jar"
path = "../xsd-cli/build/libs/xsd-cli-1.2.1-SNAPSHOT.jar"

[[dependency]]
path = "../xsd-core/build/libs/xsd-core-1.2.0.jar"
path = "../xsd-core/build/libs/xsd-core-1.2.1-SNAPSHOT.jar"

2 changes: 1 addition & 1 deletion module-ballerina-xsd/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.11.0"
org = "ballerina"
name = "xsdtool"
version = "1.2.0"
version = "1.2.1"
authors = ["Ballerina"]
keywords = ["xsd", "xsd-tool"]
repository = "https://github.com/ballerina-platform/xsd-tools"
Expand Down
2 changes: 1 addition & 1 deletion module-ballerina-xsd/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.11.0"
[[package]]
org = "ballerina"
name = "xsdtool"
version = "1.2.0"
version = "1.2.1"
modules = [
{org = "ballerina", packageName = "xsdtool", moduleName = "xsdtool"}
]
Expand Down
26 changes: 16 additions & 10 deletions xsd-core/src/main/java/io/ballerina/xsd/core/visitor/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,24 @@ public final class Utils {
private static final String WHITESPACE_PATTERN = "\\s";
private static final String SPECIAL_CHARS_PATTERN = "[!@$%^&*()_\\-|]";
public static final String NMTOKEN = "NMTOKEN";
public static final String NMTOKENS = "NMTOKENS";
public static final String ENTITY = "ENTITY";
public static final String ENTITIES = "ENTITIES";
public static final String NAME = "Name";
public static final String IDREF = "IDREF";
public static final String IDREFS = "IDREFS";
public static final String ANYDATA = "anydata";
public static final String ANY_TYPE = "anyType";
public static final String ANY_SIMPLE_TYPE = "anySimpleType";
public static final String ANY_ATOMIC_TYPE = "anyAtomicType";
private static final Set<String> SIMPLE_TYPES = Set.of(
TIME, DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR, STRING, LANGUAGE, DURATION,
INTEGER, LONG, NEGATIVE_INTEGER, NON_POSITIVE_INTEGER, POSITIVE_INTEGER, SHORT,
UNSIGNED_LONG, UNSIGNED_INT, UNSIGNED_SHORT, UNSIGNED_BYTE, INT, BASE64_BINARY,
BOOLEAN, FLOAT, DOUBLE, DECIMAL, ANY_URI, NON_NEGATIVE_INTEGER, G_MONTH_DAY, G_DAY,
G_MONTH, NORMALIZED_STRING, TOKEN, NCNAME, QNAME, NOTATION, NMTOKEN, NMTOKENS,
IDREF, IDREFS, ID, HEX_BINARY, BYTE, NAME, ENTITY, ENTITIES
);

public static String addNamespace(XSDVisitorImpl xsdVisitor, String namespace) {
if (Objects.equals(namespace, EMPTY_STRING)) {
Expand Down Expand Up @@ -186,9 +198,9 @@ public static String deriveType(Node node) {

public static String typeGenerator(String typeName) {
switch (typeName) {
case TIME, DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR, STRING, LANGUAGE,
DURATION, ANY_URI, G_MONTH_DAY, NMTOKEN, IDREF, IDREFS, G_DAY, G_MONTH, NORMALIZED_STRING,
TOKEN, NCNAME, QNAME, NOTATION, BASE64_BINARY, HEX_BINARY, BYTE, ID -> {
case TIME, DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR, STRING, LANGUAGE, DURATION, ANY_URI, G_MONTH_DAY,
NMTOKEN, NMTOKENS, IDREF, IDREFS, G_DAY, G_MONTH, NORMALIZED_STRING, TOKEN, NCNAME, QNAME,
NOTATION, BASE64_BINARY, HEX_BINARY, BYTE, ID, NAME, ENTITY, ENTITIES -> {
return STRING;
}
case INTEGER, LONG, NEGATIVE_INTEGER, NON_POSITIVE_INTEGER, POSITIVE_INTEGER, SHORT,
Expand All @@ -215,13 +227,7 @@ public static String typeGenerator(String typeName) {

public static boolean isSimpleType(String type) {
String typeName = type.contains(COLON) ? type.substring(type.indexOf(COLON) + 1) : type;
String[] simpleTypes = {
TIME, DATE_TIME, DATE, G_YEAR_MONTH, G_YEAR, STRING, LANGUAGE, DURATION,
INTEGER, LONG, NEGATIVE_INTEGER, NON_POSITIVE_INTEGER, POSITIVE_INTEGER, SHORT,
UNSIGNED_LONG, UNSIGNED_INT, UNSIGNED_SHORT,
UNSIGNED_BYTE, INT, BASE64_BINARY, BOOLEAN, FLOAT, DOUBLE, DECIMAL, ANY_URI, NON_NEGATIVE_INTEGER
};
return Arrays.stream(simpleTypes).toList().contains(typeName);
return SIMPLE_TYPES.contains(typeName);
}

public static Iterable<Node> asIterable(NodeList nodeList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ private static Stream<Object[]> provideTestPaths() {
"41_elements_with_attribute_group.bal"},
new Object[] {new String[] {"42_elements_with_any.xsd"}, "42_elements_with_any.bal"},
new Object[] {new String[] {"43_elements_with_include_base.xsd", "43_elements_with_include.xsd"},
"43_elements_with_include.bal"}
"43_elements_with_include.bal"},
new Object[] {new String[] {"44_elements_with_builtin_string_types.xsd"},
"44_elements_with_builtin_string_types.bal"}
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ballerina/data.xmldata;

@xmldata:Namespace {uri: "http://namespace.org/"}
public type TokenList record {|
string \#content;
|};

@xmldata:Namespace {uri: "http://namespace.org/"}
public type EntityRef record {|
string \#content;
|};

@xmldata:Namespace {uri: "http://namespace.org/"}
public type EntityRefs record {|
string \#content;
|};

@xmldata:Namespace {uri: "http://namespace.org/"}
public type NameVal record {|
string \#content;
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://namespace.org/">
<xs:element name="TokenList" type="xs:NMTOKENS"/>
<xs:element name="EntityRef" type="xs:ENTITY"/>
<xs:element name="EntityRefs" type="xs:ENTITIES"/>
<xs:element name="NameVal" type="xs:Name"/>
</xs:schema>