• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to remove spaces in xml

 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i tried to delete an element in xml..for that i used servlet coding...it is getting deleted but blank spaces are remaining i dont want that blank spaces..can any one do me needfull..here is my code..can any one check it



thanks in advance,
madhu
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i had edited the code
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please choose the correct forum for XML related questions. I'll move this from the Servlets forum to the XML forum.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code is in servlet...from servlet im deleting xml file
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

madhuri kunchala wrote:the code is in servlet...from servlet im deleting xml file


(His point was that the question has nothing to do with servlets, and everything to do with XML. You could be calling the same code from Swing, an Applet, a console program, anywhere.)
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define "it doesn't remove spaces". At what point do you see the spaces? What happens if you print out the node value immediately after removing the spaces?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k..i got it..it is moved to xml..no one is responding to my question...
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is going to delete and spaces are left..example here is my sample xml

'original xml file'



after doing delete of the pack..the output is




im getting spaces like this

</MA05>


<MA00>
i.e after end of first pack and start of next pack..
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as XML is concerned, those spaces (and line breaks and tabs) are valid Nodes of type TEXT and are part of the DOM.

Bill
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And why does it matter if there's whitespace between elements?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i dont need that spaces...can you suggest me how to delete that spaces..here is my code..



can you check my code and tell me where to do modifications...i tried.but i didnt got it...waiting for your reply.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you care if there are spaces?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because client needs full xml file with no whitespaces..thats why..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then they're parsing XML wrong.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you provide me where is wrong i'll do it ..im so thankful if you provide me the solution..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd probably just post-process the output file since you're not in control of how the transformer chooses to render XML (unless you are, in which case figure out what property needs to be set).
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

madhuri kunchala wrote:can you provide me where is wrong i'll do it ..im so thankful if you provide me the solution..


Whoever is *PARSING* it is wrong. Inter-nodal whitespace should be completely ignored if it's being parsed correctly.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need is to remove blankspaces if i delete any pack....i used trim() concept at line 18..but not working..it is not taking trim() function...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Omg.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stop and think.

You already have the information you need - the offending blank lines are a child node of type TEXT_NODE and a direct child of the PACKS element (document root ?)

You want the TEXT_NODE between your MAxx Elements to only have one formatting crlf instead of several.

Now - how those extra lines got in there is not clear from my cursory examination of your code, but you should be able to locate the TEXT_NODE and change it.

Bill
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried according what you had suggested by unable to remove spaces..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I'd probably just post-process the output file since you're not in control of how the transformer chooses to render XML (unless you are, in which case figure out what property needs to be set).


With the caveat that this is silly, because inter-nodal space shouldn't matter.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you doing this:


See javax.xml.transform.OutputKeys - a yes authorizes the transformer to insert additional whitespace.



Bill
(I should have noticed that before, sorry. My excuse is I never use that setting.)
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi good morning,
i modified my code and run my code...even though im getting the same problem....here is my modified code...



what should be done..inorder to remove spaces..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:

David Newton wrote:I'd probably just post-process the output file since you're not in control of how the transformer chooses to render XML (unless you are, in which case figure out what property needs to be set).


With the caveat that this is silly, because inter-nodal space shouldn't matter.

 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to William Brogden, i had changed my transformer code...eventhough same problem arises....is there any solution for my problem..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:

David Newton wrote:

David Newton wrote:I'd probably just post-process the output file since you're not in control of how the transformer chooses to render XML (unless you are, in which case figure out what property needs to be set).


With the caveat that this is silly, because inter-nodal space shouldn't matter.

 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose you could always treat it as a pure text problem, reading the file line by line and discarding blank lines, writing the lines with content to a new file, which what David meant by "post process".

Or the equivalent in memory with a custom OutputStream - however I suspect that your code or the transformer you are using is somehow introducing the extra blank lines.

Bill
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i checked line by line...but i didnt see that where to remove the blank lines...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my code..i had some modifications inorder to remove whitespaces in xml file..but it is not get deleted...can you suggest me the solution

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Er. Anyway, go through the output file line by line and remove any lines that are entirely whitespace, just like William already said. Still with the caveat that this should in no way be necessary if the XML is being parsed in any reasonable way. You realize you're talking about non-significant whitespace between elements, right?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
According to William and David i checked line by line and i used 'OutputStream' also..but im unable to remove the spaces...here is my modified code...can anyone help in this issue..



waiting for the reply..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Open the XML file you've written.
2) Read it line-by-line
3) For each line that is not only whitespace write it to a new XML file.

Now do you understand?
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic