Whitespace removal from XML

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

Whitespace removal from XML

by harryh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Not scrictly a Lift question, but does anyone have a library they like
(or is there something in scalalib I'm not aware of) that will remove
whitespace from XML?

<foo>
  <bar>hello world</bar>
</foo>

to:

<foo><bar>hello world</bar></foo>

-harryh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Whitespace removal from XML

by harryh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Answering my own question, I wrote this.  I think it should do what I
want:

def compactXml(node: Node): Node = node match {
  case Elem(p, l, a, s, children @ _*) => Elem(p, l, a, s, children.map
(compactXml(_)) :_*)
  case Text(data) => Text(data.trim)
  case x => x
}

-harryh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Whitespace removal from XML

by Bryan Germann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Also see trimProper in
http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_7_7_final/src/library/scala/xml/Utility.scala?view=markup

--Bryan

On Mon, Nov 9, 2009 at 5:47 PM, harryh <harryh@...> wrote:

>
> Answering my own question, I wrote this.  I think it should do what I
> want:
>
> def compactXml(node: Node): Node = node match {
>  case Elem(p, l, a, s, children @ _*) => Elem(p, l, a, s, children.map
> (compactXml(_)) :_*)
>  case Text(data) => Text(data.trim)
>  case x => x
> }
>
> -harryh
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---