Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML should have a method to retrieve compact xml #35

Closed
krzyk opened this issue Oct 13, 2014 · 31 comments
Closed

XML should have a method to retrieve compact xml #35

krzyk opened this issue Oct 13, 2014 · 31 comments

Comments

@krzyk
Copy link

krzyk commented Oct 13, 2014

Both XMLDocument and StrictXML should have a method to return XML in more compact way (without unnecessary white spaces)

@krzyk
Copy link
Author

krzyk commented Oct 27, 2014

@dmarkov ping

@dmarkov
Copy link

dmarkov commented Oct 28, 2014

I'm aware of the task, give me some time to find a developer...

@dmarkov
Copy link

dmarkov commented Oct 28, 2014

thanks for the report, I topped your acc for 15 mins, payment ID 000-52e05536

yegor256 pushed a commit that referenced this issue Nov 21, 2014
@yegor256
Copy link
Member

@rultor release, tag is 0.14

@rultor
Copy link
Contributor

rultor commented Nov 21, 2014

@rultor release, tag is 0.14

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Nov 21, 2014

@rultor release, tag is 0.14

@yegor256 Oops, I failed. You can see the full log here (spent 8min)

yegor256 pushed a commit that referenced this issue Nov 21, 2014
@yegor256
Copy link
Member

@rultor release, tag is 0.14

@rultor
Copy link
Contributor

rultor commented Nov 21, 2014

@rultor release, tag is 0.14

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Nov 21, 2014

@rultor release, tag is 0.14

@yegor256 Done! FYI, the full log is here (took me 11min)

@yegor256
Copy link
Member

@krzyk look at XSLDocument.STRIP. I think this is what you're looking for

@krzyk
Copy link
Author

krzyk commented Nov 22, 2014

@yegor256 Unfortunately it introduces new lines between the tags.

@yegor256
Copy link
Member

@krzyk true... let me think about something else

@dmarkov
Copy link

dmarkov commented Dec 26, 2014

@jenya this task is yours, please help (see our key principles of work). If you have any technical questions, don't hesitate to ask right here

Task's budget is 30 mins (see this for explanation)

@yegor256
Copy link
Member

yegor256 commented Jan 8, 2015

@dmarkov please assign someone else

@dmarkov
Copy link

dmarkov commented Jan 12, 2015

@dmarkov please assign someone else

@yegor256 no problem, I'll try to find somebody else

@dmarkov
Copy link

dmarkov commented Jan 13, 2015

@pinaf this task is yours, please help (see our key principles of work). If you have any technical questions, don't hesitate to ask right here... Task's budget is 30 mins (see this for explanation)

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@dmarkov @yegor256 I can't fix the line break after tags issue with XSL. Setting indent="no" in the XSL should handle this as can be seen here, but it seems the default java implementation of the XSL processor does not honor that. Suggestions?

@yegor256
Copy link
Member

@pinaf if it's a bug in Java XSL implementation, this is not our problem. But I think we're using Saxon in this library, aren't we?

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@yegor256 I don't see any reference to saxon in pom.xml.

@yegor256
Copy link
Member

@pinaf in that case, implement it with indent=no and test with Saxon (or some other Java XSL implementation). And document in Javadoc, that this may not work with standard Java implementation.

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@yegor256 turns out the problem was something else. When the source XML already has line breaks, STRIP doesn't remove them. indent=no just keeps the XSL processor from adding indentation of its own. Also, STRIP doesn't ADD line breaks - those come from the call to trans.setOutputProperty(OutputKeys.INDENT, "yes") inside the method XMLDocument.asString, which gets called whenever you construct a XMLDocument from a String. Here's what STRIP does:

<hi>  <dude>  A </dude>      </hi>

yields

<hi><dude>  A </dude></hi>

But

<hi>
    <dude>  A </dude>
   </hi>

which already contains linebreaks, yields

<hi>
<dude>  A </dude>
</hi>

I can't get the XSL processor to strip those line breaks. Let me know if you just want STRIP to be used - if not, please give this taks to someone else who knows XSL.

@yegor256
Copy link
Member

@pinaf looks like the problem is not with XSL, but with XMLDocument#toString(), right? This method adds indentation. Maybe we can introduce a new method XML#compact(), which will return another instance of XML, that prints itself without indentation:

new XMLDocument("<hi>\n<a>hey</a></hi>").compact().toString();

This will solve the problem, right?

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@yegor256 toString just returns a String field called xml which gets calculated in asString with indentation. xml is the internal representation (in String form) of the XML document and it is calculated from a Node given to the constructor. Once asString is finished, xml can no longer be changed (final) and since the original Node element was not kept, there is no way to go back to a pre-indentation String. We either need to keep the original Node element and use it to generate a String with no indentation or we change the implementation of asString so that it doesn't indent.

@yegor256
Copy link
Member

@pinaf I see. So, we should document all this in the Javadoc of STRIP and call it a day. We simply can't provide the functionality asked by @krzyk. If he needs a compact (without indentation) presentation of an XML document, he should get Node from XML using node() method and then convert it into string using native Java transformer.

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@yegor256 Alright, but calling node() wouldn't work either because it creates a new Node from the String xml already constructed with indentation.

Is it alright to also add a link to this discussion in the Javadoc or is that something you don't like?

@yegor256
Copy link
Member

@pinaf it's better to keep the source code detached from the discussion tickets

@pinaf
Copy link
Contributor

pinaf commented Jan 13, 2015

@dmarkov @krzyk PR #42

@pinaf
Copy link
Contributor

pinaf commented Jan 16, 2015

@krzyk @dmarkov merged. please close.

@krzyk krzyk closed this as completed Jan 16, 2015
@dmarkov dmarkov added the @pinaf label Jan 19, 2015
@pinaf
Copy link
Contributor

pinaf commented Jan 20, 2015

@dmarkov payment?

@dmarkov
Copy link

dmarkov commented Jan 20, 2015

@pinaf I just added 30 mins to your account, many thanks for your contribution..... added +30 to your rating, now it is equal to +105

@pinaf
Copy link
Contributor

pinaf commented Jan 20, 2015

@dmarkov thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants