class XMLToScala extends AnyRef
This class uses Scala reflection to parse XML into user-defined case classes.
The effect is that the classes encode the XML grammar, and the parser picks the corresponding class for each XML tag. This is kind of the opposite of generating a parser, where the grammar is fixed and the classes are generated.
- Source
- XMLToScala.scala
- Alphabetic
- By Inheritance
- XMLToScala
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
XMLToScala(pkg: String)
- pkg
the full name of the package in which the case classes are declared An XML node is parsed into a case class instance as follows * the case class whose name is the tag name is used except that * XML - is treated as Scala _ * XML names that are Scala reserved words are prefixed by 'XML' in Scala * the arguments to the class (technically: the single apply method of the companion object) are computed as follows: * k: String: the value of the attribute with key s, or the content of the child with tag k, ("" if neither present) * k: Int: accordingly * k: Boolean: accordingly (false if not present) * t: A where A is one the case classes: recursive call on the single child of the child with tag t * t: Option[A]: accordingly, but the child may be absent * t: List[A]: accordingly but the child may have any number of children * t: G <: Group: All arguments of G are computed and an instance of G constructed. * _a: A, Option[A], List[A] (where A may be a subtype of Group): like the t-cases above but taking the next available child(ren) of type A Effectively, all fields of G are imported into the current case class. The type A does not have to be a case class, e.g., the elements in a list can have the tags of subclasses of A.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
apply(node: Node): Any
parse a Node
-
def
apply(file: File): Any
read and parse a file
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
scalaName(s: String): String
convert xml tag/key names to Scala id names
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
xmlName(s: String): String
convert Scala id names to xml tag/key names