How to embed JSON doc in XML field

1,411 views
Skip to first unread message

sc28

unread,
Sep 16, 2014, 4:36:09 PM9/16/14
to golan...@googlegroups.com
http://play.golang.org/p/3Nbkup5fOa

I'm trying to embed a JSON document as a value of an XML element - when Marshaling the XML document, it escapes the JSON string - how can I prevent this?

I want the result to look like:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <elem>
    <Files>{"FileName":"hello","ID":"world"}</Files>
  </elem>
</Package>

instead of:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <elem>
    <Files>{&#34;FileName&#34;:&#34;hello&#34;,&#34;ID&#34;:&#34;world&#34;}</Files>
  </elem>
</Package>

Thanks!

Henrik Johansson

unread,
Sep 16, 2014, 4:50:57 PM9/16/14
to sc28, golang-nuts

cdata perhaps?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

C Banning

unread,
Sep 17, 2014, 4:43:51 AM9/17/14
to golan...@googlegroups.com

sc28

unread,
Sep 17, 2014, 9:30:29 AM9/17/14
to golan...@googlegroups.com
Thanks All!

For my case, the htmlUnescapeString function works perfectly.
Reply all
Reply to author
Forward
0 new messages