[Lift] Re: Encoding raw HTML into single JSON element

2010-02-11 Thread Mike
Solved by coworker:

private def handleMarkup(xml: Node): Node = {
(xml map {
  case Elem(prefix, "markup", attributes, scope, children @ _*) =>
{
Utility.trim(Elem(prefix, "markup", attributes, scope,
Text(children.foldLeft("")(_ + _.toString
  }
  case Elem(prefix, label, attributes, scope, children @ _*) => {
Elem(prefix, label, attributes, scope,
children.map(handleMarkup(_)) : _*)
  }
  case x => x
}).first
}

On Feb 11, 1:51 pm, Mike  wrote:
> Looking for some advise about encoding raw HTML to JSON.
>
> Here as some sample XML similar to what we are using:
> 846
> Mike
> 
>     
>         testing
>     
> 
>
> When converting this XML to JSON I would like the "markup" element and
> all of it's children to be returned as a big string. For example:
> {"id": 846, "name": "Mike", "markup", "testing"}
>
> Right now it always tries to parse the children, resulting in
> something similar to:
> {"id": 846, "name": "Mike", "markup":{"div":{"h1":"testing"}}
>
> Any insights?

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



[Lift] Re: Encoding raw HTML into single JSON element

2010-02-11 Thread Joni Freeman
Mike,

Here's one idea. Convert the XML to JSON and the fix the "markup"
field. Something like:

toJson(xml) map {
  case JField("markup", _) => JField("markup", JString((xml \\
"markup").toString))
  case x => x
}

Does that work for you?

Cheers Joni

On Feb 11, 8:51 pm, Mike  wrote:
> Looking for some advise about encoding raw HTML to JSON.
>
> Here as some sample XML similar to what we are using:
> 846
> Mike
> 
>     
>         testing
>     
> 
>
> When converting this XML to JSON I would like the "markup" element and
> all of it's children to be returned as a big string. For example:
> {"id": 846, "name": "Mike", "markup", "testing"}
>
> Right now it always tries to parse the children, resulting in
> something similar to:
> {"id": 846, "name": "Mike", "markup":{"div":{"h1":"testing"}}
>
> Any insights?

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