minor XML question

View: New views
3 Messages — Rating Filter:   Alert me  

minor XML question

by Normen Mueller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

He,

    is it possible to serialize XML without additional closing elements?  For example, if val xml = <a><b/></a>, then the serialization is <a><b></b></a>, rather than <a><b/></a>.

Cheers,
  /nm

Re: minor XML question

by Burak Emir-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

no, nobody wants to send a patch that would parameterize the printing routines. I would suggest subclassing the PrettyPrinter class.

a hacky alternative is to use a tree transform that replaces every empty element b with scala.xml.Unparsed("<b/>").

Burak

On Tue, Aug 26, 2008 at 10:28 AM, Normen Müller <normen.mueller@...> wrote:
He,

  is it possible to serialize XML without additional closing elements?  For example, if val xml = <a><b/></a>, then the serialization is <a><b></b></a>, rather than <a><b/></a>.

Cheers,
 /nm



--
Burak Emir
--
http://burak.emir.googlepages.com

Re: minor XML question

by Normen Mueller :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Burak Emir wrote:
> no, nobody wants to send a patch that would parameterize the printing
> routines. I would suggest subclassing the PrettyPrinter class.
>
That's more or less what I did.  But, I sub-classed PrettyPrinter and wrote my own xml.Utility, so that:

protected def traverse(node: Node,pscope: NamespaceBinding,ind: Int): Unit =
[...]
case _ =>
        val test = {
          val sb = new StringBuilder()
          nrm.xml.Utility.toXML(node, pscope, sb, false)

nrm.xml.Utility.toXML takes care of the rest:

[...[
case _  =>
        sb.append('<')
        x.nameToString(sb)
        if (x.attributes ne null) x.attributes.toString(sb)
        x.scope.toString(sb, pscope)
        if(! x.child.isEmpty) {
          [...]
        } else sb.append("/>")

That's works quite well for me, but I don't know if this is the correct/ most elegant way.

Cheers,
  /nm