- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
appending xml Elements recursively
Fri, 2010-03-26, 15:11
Hi,
I was wondering what I needed to change to following code snippet in order to get it to work properly:
case class FileComponent(file: File) extends TreeComponent[File, FileComponent]{
def isComposite = file.isDirectory
def subComponents = for {
aFile <- file.listFiles
} yield FileComponent(aFile)
def component = FileComponent(file)
def value = file
def toXML: Elem = {
{value.getName()}
{
if (isComposite) {
{
subComponents.foreach(_.toXML) //this is not appending the elements to their parent... but I don’t know how to reference the context node in order to append it's children
}
}
}
}
}
Kind regards,
Robby Pelssers
Ok... I just found the answer :-)
case class FileComponent(file: File) extends TreeComponent[File, FileComponent]{
def isComposite = file.isDirectory
def subComponents = for {
aFile <- file.listFiles
} yield FileComponent(aFile)
def component = FileComponent(file)
def value = file
def toXML: Elem = {
{value.getName()}
{
if (isComposite) {
{
for { subComponent <- subComponents } yield subComponent.toXML
}
}
}
}
}
-----Original Message-----
From: Robby Pelssers [mailto:robby.pelssers@ciber.com]
Sent: Friday, March 26, 2010 3:13 PM
To: scala-user@listes.epfl.ch
Subject: [scala-user] appending xml Elements recursively
Hi,
I was wondering what I needed to change to following code snippet in order to get it to work properly:
case class FileComponent(file: File) extends TreeComponent[File, FileComponent]{
def isComposite = file.isDirectory
def subComponents = for {
aFile <- file.listFiles
} yield FileComponent(aFile)
def component = FileComponent(file)
def value = file
def toXML: Elem = {
{value.getName()}
{
if (isComposite) {
{
subComponents.foreach(_.toXML) //this is not appending the elements to their parent... but I don’t know how to reference the context node in order to append it's children
}
}
}
}
}
Kind regards,
Robby Pelssers