scala.xml

object Utility

[source: scala/xml/Utility.scala]

object Utility
extends TokenTests
The Utility object provides utility functions for processing instances of bound and not bound XML classes, as well as escaping text nodes.
Author
Burak Emir
Method Summary
def appendEscapedQuoted (s : java.lang.String, sb : StringBuilder) : StringBuilder
Appends "s" and escapes and " i s with \"
def appendQuoted (s : java.lang.String, sb : StringBuilder) : StringBuilder
Appends "s" if string s does not contain ", 's' otherwise.
def appendQuoted (s : java.lang.String) : java.lang.String
def checkAttributeValue (value : java.lang.String) : java.lang.String
Returns null if the value is a correct attribute value, error message if it isn't.
def collectNamespaces (n : Node, set : Set[java.lang.String]) : Unit
Adds all namespaces in node to set.
def collectNamespaces (nodes : Seq[Node]) : Set[java.lang.String]
Returns a set of all namespaces used in a sequence of nodes and all their descendants, including the empty namespaces.
final def escape (text : java.lang.String, s : StringBuilder) : StringBuilder
Appends escaped string to s.
final def escape (text : java.lang.String) : java.lang.String
Escapes the characters < > & and " from string.
def getName (s : java.lang.String, index : Int) : java.lang.String
def hashCode (pre : java.lang.String, label : java.lang.String, attribHashCode : Int, scpeHash : Int, children : Seq[Node]) : Int
Returns a hashcode for the given constituents of a node
def parseAttributeValue (value : java.lang.String) : Seq[Node]
new
def parseCharRef (ch : () => Char, nextch : () => Unit, reportSyntaxError : (java.lang.String) => Unit) : java.lang.String
     CharRef ::= "&#" '0'..'9' {'0'..'9'} ";"
               | "&#x" '0'..'9'|'A'..'F'|'a'..'f' { hexdigit } ";"
   
final def prefix (name : java.lang.String) : Option[java.lang.String]
Returns prefix of qualified name if any.
def publicLiteralToString (s : java.lang.String) : java.lang.String
def publicLiteralToString (sb : StringBuilder, s : java.lang.String) : StringBuilder
def sequenceToXML (children : Seq[Node], pscope : NamespaceBinding, sb : StringBuilder, stripComment : Boolean) : Unit
def sort (md : MetaData) : MetaData
returns a sorted attribute list
def sort (n : Node) : Node
returns the node with its attribute list sorted alphabetically (prefixes are ignored)
def systemLiteralToString (sb : StringBuilder, s : java.lang.String) : StringBuilder
def systemLiteralToString (s : java.lang.String) : java.lang.String
def toXML (n : Node) : java.lang.String
Returs the string representation of an XML node, with comments stripped the comments.
def toXML (n : Node, stripComment : Boolean) : java.lang.String
Return the string representation of a Node. uses namespace mapping from defaultPrefixes(n).
def toXML (x : Node, pscope : NamespaceBinding, sb : StringBuilder, stripComment : Boolean) : Unit
Appends a tree to the given stringbuffer within given namespace scope.
def trim (x : Node) : Node
trims an element - call this method, when you know that it is an element (and not a text node) so you know that it will not be trimmed away. With this assumption, the function can return a Node, rather than a Seq[Node]. If you don't know, call trimProper and account for the fact that you may get back an empty sequence of nodes. precondition: node is not a text node (it might be trimmed)
def trimProper (x : Node) : Seq[Node]
trim a child of an element. Attribute values and Atom nodes that are not Text nodes are unaffected.
final def unescape (ref : java.lang.String, s : StringBuilder) : StringBuilder
Appends unescaped string to s, amp becomes & lt becomes < etc..
def view (s : java.lang.String) : Text
Methods inherited from TokenTests
isSpace, isSpace, isNameChar, isNameStart, isName, isPubIDChar, isValidIANAEncoding, checkSysID, checkPubID
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
def trim(x : Node) : Node
trims an element - call this method, when you know that it is an element (and not a text node) so you know that it will not be trimmed away. With this assumption, the function can return a Node, rather than a Seq[Node]. If you don't know, call trimProper and account for the fact that you may get back an empty sequence of nodes. precondition: node is not a text node (it might be trimmed)

def trimProper(x : Node) : Seq[Node]
trim a child of an element. Attribute values and Atom nodes that are not Text nodes are unaffected.

def sort(md : MetaData) : MetaData
returns a sorted attribute list

def sort(n : Node) : Node
returns the node with its attribute list sorted alphabetically (prefixes are ignored)

@deprecated

def view(s : java.lang.String) : Text
Deprecated
a string might also be Atom(s) - define your own conversion

final def escape(text : java.lang.String) : java.lang.String
Escapes the characters < > & and " from string.
Parameters
text - ...
Returns
...

final def escape(text : java.lang.String, s : StringBuilder) : StringBuilder
Appends escaped string to s.
Parameters
text - ...
s - ...
Returns
...

final def unescape(ref : java.lang.String, s : StringBuilder) : StringBuilder
Appends unescaped string to s, amp becomes & lt becomes < etc..
Parameters
ref - ...
s - ...
Returns
null if ref was not a predefined entity.

def collectNamespaces(nodes : Seq[Node]) : Set[java.lang.String]
Returns a set of all namespaces used in a sequence of nodes and all their descendants, including the empty namespaces.
Parameters
nodes - ...
Returns
...

def collectNamespaces(n : Node, set : Set[java.lang.String]) : Unit
Adds all namespaces in node to set.
Parameters
n - ...
set - ...

def toXML(n : Node) : java.lang.String
Returs the string representation of an XML node, with comments stripped the comments.
Parameters
n - the XML node
Returns
the string representation of node n.
See Also
"toXML(Node, Boolean)"

def toXML(n : Node, stripComment : Boolean) : java.lang.String
Return the string representation of a Node. uses namespace mapping from defaultPrefixes(n).
Parameters
n - the XML node
stripComment - ...
Returns
...
Todo
define a way to escape literal characters to &xx; references

def toXML(x : Node, pscope : NamespaceBinding, sb : StringBuilder, stripComment : Boolean) : Unit
Appends a tree to the given stringbuffer within given namespace scope.
Parameters
n - the node
pscope - the parent scope
sb - stringbuffer to append to
stripComment - if true, strip comments

def sequenceToXML(children : Seq[Node], pscope : NamespaceBinding, sb : StringBuilder, stripComment : Boolean) : Unit
Parameters
children - ...
pscope - ...
sb - ...
stripComment - ...

final def prefix(name : java.lang.String) : Option[java.lang.String]
Returns prefix of qualified name if any.
Parameters
name - ...
Returns
...

def hashCode(pre : java.lang.String, label : java.lang.String, attribHashCode : Int, scpeHash : Int, children : Seq[Node]) : Int
Returns a hashcode for the given constituents of a node
Parameters
uri -
label -
attribHashCode -
children -

def systemLiteralToString(s : java.lang.String) : java.lang.String
Parameters
s - ...
Returns
...

def systemLiteralToString(sb : StringBuilder, s : java.lang.String) : StringBuilder
Parameters
sb - ...
s - ...
Returns
...

def publicLiteralToString(s : java.lang.String) : java.lang.String
Parameters
s - ...
Returns
...

def publicLiteralToString(sb : StringBuilder, s : java.lang.String) : StringBuilder
Parameters
sb - ...
s - ...
Returns
...

def appendQuoted(s : java.lang.String) : java.lang.String

def appendQuoted(s : java.lang.String, sb : StringBuilder) : StringBuilder
Appends "s" if string s does not contain ", 's' otherwise.
Parameters
s - ...
sb - ...
Returns
...

def appendEscapedQuoted(s : java.lang.String, sb : StringBuilder) : StringBuilder
Appends "s" and escapes and " i s with \"
Parameters
s - ...
sb - ...
Returns
...

def getName(s : java.lang.String, index : Int) : java.lang.String
Parameters
s - ...
index - ...
Returns
...

def checkAttributeValue(value : java.lang.String) : java.lang.String
Returns null if the value is a correct attribute value, error message if it isn't.
Parameters
value - ...
Returns
...

def parseAttributeValue(value : java.lang.String) : Seq[Node]
new
Parameters
value - ...
Returns
...

def parseCharRef(ch : () => Char, nextch : () => Unit, reportSyntaxError : (java.lang.String) => Unit) : java.lang.String
     CharRef ::= "&#" '0'..'9' {'0'..'9'} ";"
               | "&#x" '0'..'9'|'A'..'F'|'a'..'f' { hexdigit } ";"
   

see [66]

Parameters
ch - ...
nextch - ...
reportSyntaxError - ...
Returns
...