Coder Social home page Coder Social logo

Xml formatting about sortpom HOT 12 CLOSED

delanym avatar delanym commented on July 26, 2024
Xml formatting

from sortpom.

Comments (12)

delanym avatar delanym commented on July 26, 2024

image

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Have you tried the indentSchemaLocation parameter?

from sortpom.

delanym avatar delanym commented on July 26, 2024

That results in

-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

I need each attribute on its own line because, although not applicable for poms, other xml files sometimes have many attributes on a tag.

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Let me have a look

from sortpom.

create-issue-branch avatar create-issue-branch commented on July 26, 2024

Branch issue-267-Xml_formatting created!

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

I did some experiments with this. I have some form of functionality, but it breaks existing tests.
The test case is that somebody adds an xml namespace at a lower level of the POM file. Not very realistic, but it is possible.
The indentation of the namespace will also be (normal indent * 2) + 1 space character which is not ideal.
Feel free to check out the branch and try out the code for yourself.

from sortpom.

delanym avatar delanym commented on July 26, 2024

@Ekryd how do I configure it though?

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

Check out the branch, compile it and use the parameter indentSchemaLocation to get the extra line breaks (this is just a concept code)

from sortpom.

delanym avatar delanym commented on July 26, 2024

You asked me to try out indentSchemaLocation parameter earlier. What have you done on the branch to get each attribute on its own line, or leave the line breaks alone?

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

The branch makes sure that each attribute gets its own line:

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

I cannot preserve line breaks, as the whole xml file is parsed as a DOM tree and recreated completely during sorting.

from sortpom.

delanym avatar delanym commented on July 26, 2024

Hi Björn. I don't know how you got that output. Using the released 3.2.1, I get either all attributes on one line or, with indentSchemaLocation to true, 2 lines. I don't get 3 lines - each attribute on its own line.

I tried changing

diff --git a/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java b/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
index 67dc29d..e0b3cd7 100644
--- a/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
+++ b/sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
@@ -99 +99 @@ class PatchedXMLWriter extends XMLWriter {
-    if (indentSchemaLocation && "xsi:schemaLocation".equals(qualifiedName)) {
+    if (indentSchemaLocation) {

the test failed with

[ERROR] Failures: 
[ERROR]   IndentationTest.otherAttributeShouldNotBeIndented:103 expected: <<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <Gurka xmlns="" key="value"></Gurka>
</project>
> but was: <<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <Gurka xmlns=""
     key="value"></Gurka>
</project>
>

Since it breaks before key but not xmlns:xsi Im led to believes its only processing attributes in the default namespace?

from sortpom.

Ekryd avatar Ekryd commented on July 26, 2024

You have to use git to checkout the branch issue-267-Xml_formatting in order to see the changes. The branch should compile, although some tests will fail on it.

from sortpom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.