Loosing a space from an XML document

2013-06-19 Thread Stefan Kamphausen
Hi,


Recently I found myself searching for a white space which got lost 
somewhere between reading an XML file and presenting some results from that 
via a little webapp.  

I think, I could track it down to the following example:

user (clojure.pprint/pprint 
   (clojure.zip/xml-zip
(clojure.xml/parse 
 (java.io.ByteArrayInputStream. 
  (.getBytes
   root
  ok
spanHello /span spanWorld/span
  /ok
  ok
spanHello /span dear spanWorld/span
  /ok
  wheredidmyspacego
spanHello/span spanWorld/span
  /wheredidmyspacego
/root)

[{:tag :root,
  :attrs nil,
  :content
  [{:tag :ok,
:attrs nil,
:content
[{:tag :span, :attrs nil, :content [Hello ]}
 {:tag :span, :attrs nil, :content [World]}]}
   {:tag :ok,
:attrs nil,
:content
[{:tag :span, :attrs nil, :content [Hello ]}
  dear 
 {:tag :span, :attrs nil, :content [World]}]}
   {:tag :wheredidmyspacego,
:attrs nil,
:content
[{:tag :span, :attrs nil, :content [Hello]}
 {:tag :span, :attrs nil, :content [World]}]}]}
 nil]

Take a look at the last tag wheredidmyspacego.  The whitespace between 
the span tags gets lost whereas the  dear  in the second example is 
preserved including surrounding spaces.

Is this on purpose and/or expected behavior?


Regards,
Stefan

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Loosing a space from an XML document

2013-06-19 Thread Rob Day
On 19 June 2013 20:32, Stefan Kamphausen ska2...@gmail.com wrote:
 Take a look at the last tag wheredidmyspacego.  The whitespace between the
 span tags gets lost whereas the  dear  in the second example is preserved
 including surrounding spaces.

 Is this on purpose and/or expected behavior?

Stefan,

I think this is expected behaviour for XML as a whole: whitespace on
its own isn't preserved. If you look at your XML, it actually has lots
of whitespace other than the 'wheredidmyspacego' element - there's a
newline and fifteen spaces between root and ok which (quite
rightly) you don't expect to show up in the output. If whitespace on
its own were preserved, you wouldn't be able to use it to lay out your
XML like this.

See also http://www.usingxml.com/Basics/XmlSpace:

The document contains some white space that delimits various aspects
of the XML syntax. When the white space is part of the XML syntax, it
is discarded by XML parsers and not passed on to processing
applications. XML allows for unbounded white space wherever white
space is permitted in the XML syntax. This is useful for pretty
printing an XML document.

Rob

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.