Managing XML documents in a disruptive program, ignoring formatting

I need to manage XML documents in Subversion, but I don’t want to control the formatting, which can turn out differently depending on who is editing the file.

I see two solutions: Each time format the file each time with known formatting before checking. Or give svn a diff program that actively rejects formatting from the diff algorithm. Ultimately, diff should, of course, support trilateral merging, actively ignoring XML formatting.

What do you recommend?

(The same reasoning usually applies to source code files, but the problem is more complicated.)

+4
source share
4 answers

I don't have much personal experience with this setup.

For the second method (user diff), I found an example, "Description of the API for the Netopeer repository library" which is a detailed description of the installation with Subversion and, among other things, xmldiff .

For another approach, converting to a format for formats before saving to Subversion, I recommend Canonical XML as a format. For example, the xmllint tool can convert to this format:

% cat complique.xml <?xml version="1.0" encoding="utf-8"?> <toto > <truc a="1" >Machin &#x43; </truc >cafΓ©</toto> % xmllint --c14n complique.xml <toto> <truc a="1">Machin C </truc>cafΓ©</toto> 

To integrate with Subversion, you can check in pre-commit that the submitted file is equal to the canonical file. A possible such script is my pre-commit using xmllint . See also script executor for an example.

+3
source

Do you think the following two xml fragments should be the same ...?

Fragment1:

 <foo xmlns="http://foo.com/foo"> <bar>Hello</bar> </foo> 

FRAGMENT2:

 <ns1:foo xmlns:ns1="http://foo.com/foo"> <ns1:bar>Hello</ns1:bar> </ns1:foo> 

... because if you do (since these fragments have the same xml file), you need to think about writing your own diff tool.

+1
source

If formatting means spaces, you can configure svn diff to ignore spaces using the -w in the diff :

 $ svn diff -x -w [file] 

See svn help diff more details.

0
source

Just run all your developers on one page. In any case, they should all be encoded according to the same standard. If your encoders all use different formatting standards, you have problems that need to be addressed.

0
source

All Articles