Skip to content

Commit 40a3e10

Browse files
fixup! Add support for infoset dataType member
1 parent 4623076 commit 40a3e10

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

daffodil-core/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,18 @@ Differences were (path, expected, actual):
912912
res
913913
}
914914

915+
// Normalize xmlns mappings to improve comparisons. Avoids differences in whitespace,
916+
// namespace ordering, and bindings like xmlns:xsi which is optionally added by some infoset
917+
// outputters that have support for xsi:type
918+
private def normalizeMappings(mappings: String): String = {
919+
mappings
920+
.trim()
921+
.split("\\s+")
922+
.filterNot(_.startsWith("xmlns:xsi="))
923+
.sorted
924+
.mkString(" ")
925+
}
926+
915927
def computeDiffOne(
916928
an: Node,
917929
bn: Node,
@@ -950,8 +962,10 @@ Differences were (path, expected, actual):
950962
val maybeType: Option[String] = Option(typeA.getOrElse(typeB.getOrElse(null)))
951963
val nilledA = a.attribute(XSI_NAMESPACE.toString, "nil")
952964
val nilledB = b.attribute(XSI_NAMESPACE.toString, "nil")
953-
val mappingsA = if (checkNamespaces) nsbA.buildString(aParentScope).trim else ""
954-
val mappingsB = if (checkNamespaces) nsbB.buildString(bParentScope).trim else ""
965+
val mappingsA =
966+
if (checkNamespaces) normalizeMappings(nsbA.buildString(aParentScope)) else ""
967+
val mappingsB =
968+
if (checkNamespaces) normalizeMappings(nsbB.buildString(bParentScope)) else ""
955969

956970
if (labelA != labelB) {
957971
// different label

daffodil-core/src/main/scala/org/apache/daffodil/runtime1/infoset/ScalaXMLInfosetOutputter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ScalaXMLInfosetOutputter(showFreedInfo: Boolean = false)
5959
private def getScope(diElem: DIElement): NamespaceBinding = {
6060
val minScope = diElem.metadata.minimizedScope
6161
// if including xsi:type is enabled, ensure the xsi namespace is defined on the root element
62-
if (getIncludeDataType() && stack.length == 1 && minScope.getPrefix("xsi") == null) {
62+
if (getIncludeDataType() && stack.length == 1 && minScope.getURI("xsi") == null) {
6363
NamespaceBinding("xsi", XMLUtils.XSI_NAMESPACE, minScope)
6464
} else {
6565
minScope

daffodil-core/src/main/scala/org/apache/daffodil/runtime1/infoset/XMLTextInfosetOutputter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class XMLTextInfosetOutputter private (
114114
}
115115
// if including xsi:type is enabled, ensure the xsi namespace is defined on the root
116116
// element
117-
if (getIncludeDataType() && !hasStartedRoot && nsbStart.getPrefix("xsi") == null) {
117+
if (getIncludeDataType() && !hasStartedRoot && nsbStart.getURI("xsi") == null) {
118118
writer.write(" xmlns:xsi=\"" + XMLUtils.XSI_NAMESPACE + "\"")
119119
}
120120
}

0 commit comments

Comments
 (0)