Overview
Features
Download
Documentation
Community
Add-Ons & Services

DOM and whitespace

General discussion regarding the development of POCO for contributors.

DOM and whitespace

Postby chrisjones » 10 May 2008, 00:25

hey

i just started using DOMParser, ive set it to use the whitespace filter, but im still getting some whitespace. looking at the characters, its ascii values 9 and 10, which are tab and linefeed (LF).

Looking at the whitespace filter, this line:

if (*it != ' ' && *it != '
' && *it != ' ' && *it != ' ')

it doesnt handle linefeed, but it does handle tab?
Im using the following code to enable whitespace then parse the document from a string:

mParser.setFeature(DOMParser::FEATURE_WHITESPACE, true);
mDocument = mParser.parseString(xmlData);

Is there anything else i need to do? Or if its a problem with the filter can the linefeed be added? i don't know why the tabs arent being removed though. Any ideas?

thanks
Chris
chrisjones
 
Posts: 35
Joined: 28 Jan 2008, 22:01
Location: United_Kingdom

Re: DOM and whitespace

Postby guenter » 10 May 2008, 10:50

Can you show me the XML document? The whitespace filter only filters out whitespace in between tags. If you have something like
Code: Select all

<foo>
    bar
</foo>

Then the text under the foo element will still contain leading and trailing whitespace (cr/lf and spaces in this case) around "bar".
guenter
 
Posts: 1119
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: DOM and whitespace

Postby chrisjones » 10 May 2008, 17:02

thanks, heres the xml file







A XHTML Example


My Xml Title
This is a XHTML example page.




i just took the sample xml file from poco samples and changed a bit. All of the whitespace is after each tag that goes onto the next line, so between and etc
I just used notepad++ to change the format to unix, and to mac types (different line endings), and i still get the same whitespace. In the mac format, line endings are only carriage return, but i still seem to get linefeeds. viewing it in a hex editor, theyre definatly CR, not LF. It is also encoded in UTF-8, although ANSI has the same problem (not sure if that makes a difference at all).
chrisjones
 
Posts: 35
Joined: 28 Jan 2008, 22:01
Location: United_Kingdom

Re: DOM and whitespace

Postby chrisjones » 10 May 2008, 17:06

erm, ok that doesnt display properly on this forum and i cant edit my post. How can i add my code like your example?
chrisjones
 
Posts: 35
Joined: 28 Jan 2008, 22:01
Location: United_Kingdom

Re: Re: DOM and whitespace

Postby alex » 10 May 2008, 18:47

> erm, ok that doesnt display properly on this forum and i cant edit my post. How can i add my code like your example?

~np~
Code: Select all
 the code
~/np~ gives:

Code: Select all
 the code
alex
 
Posts: 1117
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: DOM and whitespace

Postby chrisjones » 10 May 2008, 19:24

thanks

ok, so it still doesnt preview properly, it doesnt display any tags at all. the xml below is my file but ive removed all of the < parts so it will display, i hope this doesnt cause any problems. That is the only change ive made, if you were to add the < back onto each tag it would be what i have. Is there a way of displaying xml/html code? those code tags only seem to put a box around it?

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<ad>
   <head>
      <link rel="stylesheet" href="styles.css" type="text/css"/>
      <title>A XHTML Example
   </head>
   <body>
      <h1>My Xml Title
      <p>This is a XHTML example page.
      <img src="example.gif" width="256" height="192" alt="Example Picture" border="0"/>
   </body>
</ad>
chrisjones
 
Posts: 35
Joined: 28 Jan 2008, 22:01
Location: United_Kingdom

Re: Re: DOM and whitespace

Postby lazalong » 11 May 2008, 02:06

> ok, so it still doesnt preview properly,

@Chris It's perhaps best to put the file on our server (or any other sharing sites) and put here a link to it. You will not be able to display properly
etc.
lazalong
 
Posts: 16
Joined: 15 Feb 2008, 08:36
Location: Australia


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest