0

In our project, we wants to generate the excel report from xml which has all differences of two folders.

I tried to get the full path of a file from xml nodes, but i am confusing with node names because all parent nodes(foldercomp) have same name.

And can create xsd for this xml format , inner classes with same class names are not accepting in xsd complex types.

Can you please help me on this

Below is the bcompare xml report:

<?xml version="1.0" encoding="utf-8"?>
<bcreport created="16-11-2017 20:20:54">
<foldercomp>
    <ltpath>E:\compare\CODE1</ltpath>
    <rtpath>E:\compare\CODE2</rtpath>
    <mode>Differences</mode>
    <foldercomp>
        <lt>
            <name>Dir1</name>
            <size>696</size>
        </lt>
        <rt>
            <name>Dir1</name>
            <size>846</size>
        </rt>
        <foldercomp>
            <lt>
                <name>Dir3</name>
                <size>424</size>
            </lt>
            <rt>
                <name>Dir3</name>
                <size>431</size>
            </rt>
            <foldercomp>
                <lt>
                    <name>Dir4</name>
                    <size>281</size>
                </lt>
                <rt>
                    <name>Dir4</name>       <!-- E:\compare\CODE2\Dir1\Dir3\Dir4  -->
                    <size>288</size>
                </rt>
                <filecomp status="rtnewer">
                    <lt>
                        <name>File5 (2).txt</name>  <!-- E:\compare\CODE1\Dir1\Dir3\Dir4\File5 (2).txt -->
                        <size>139</size>
                    </lt>
                    <rt>
                        <name>File5 (2).txt</name>   <!-- E:\compare\CODE2\Dir1\Dir3\Dir4\File5 (2).txt -->
                        <size>146</size>
                    </rt>
                </filecomp>
            </foldercomp>
        </foldercomp>
        <filecomp status="rtonly">
            <rt>
                <name>File1 (1).txt</name>  <!-- E:\compare\CODE2\File1 (1).txt -->
                <size>143</size>
            </rt>
        </filecomp>
    </foldercomp>
    <foldercomp>
        <lt>
            <name>Dir2</name>
            <size>286</size>
        </lt>
        <rt>
            <name>Dir2</name>
            <size>296</size>
        </rt>
        <filecomp status="rtnewer">
            <lt>
                <name>File2.txt</name>   <!-- E:\compare\CODE1\Dir2\File2.txt -->
                <size>143</size>
            </lt>
            <rt>
                <name>File2.txt</name>   <!-- E:\compare\CODE2\Dir2\File2.txt -->
                <size>153</size>
            </rt>
        </filecomp>
    </foldercomp>
    <filecomp status="rtnewer">
        <lt>
            <name>File1 (2).txt</name>   <!-- E:\compare\CODE1\File1 (2).txt -->
            <size>132</size>
        </lt>
        <rt>
            <name>File1 (2).txt</name>  <!-- -E:\compare\CODE1\File1 (2).txt -->
            <size>139</size>
        </rt>
    </filecomp>
    <filecomp status="rtnewer">
        <lt>
            <name>File1 (3).txt</name>   <!-- E:\compare\CODE1\File1 (3).txt -->
            <size>144</size>
        </lt>
        <rt>
            <name>File1 (3).txt</name>  <!-- E:\compare\CODE2\File1 (3).txt -->
            <size>150</size>
        </rt>
    </filecomp>
</foldercomp>

lt - CODE1, rt- CODE2, foldercomp and filecomp tags for diff in folder and file

1 Answers1

1

The XML output makes sense to me. What I understand from this is:

Dir1
 |
 +-- Dir3
 |    |
 |    +Dir4
 |      |
 |      +File5
(etc)

A folder may have more folders, and a folder may have many files. For each comparison, there is left and right items. So,what you need to do is to re-think about your strategy of parsing. Each foldercomp has at least 2 (and possibly more) children, and each filecomp tag has two (or more) children.

If I were you, I would use foldercomp and filecomp open tags to increment row and column value by 1, close tags to decrement column while incrementing row by 1 in a similar fashion. And lt and rt open tags to increment row values (not column) and ignore close tag of the same. I would print folder and file names in bold, and leave the differences in normal.

The status on filecomp give you an idea about the nature of the difference. So, if it is rtnew, it means, it is added. I would use green etc.

It should be too hard to implement it via sax parser.

I hope it makes sense.

EDIT:

If you need example code for SAX parser, here it is.

I have given you the lead but I won't do your job. Sorry.

EDIT2:

Using SAX parser is really easy. Check out the documentation and example above.

Think about parsing XML with a sax parser is as a switch/case statement. When current tag is something, do what you need to do, when something else, do whatever is needed etc. You may need to keep the context as well.

switch(tag){

  foldercomp: 
    ops
  filecomp:
    ops
  rt:
    ops
  lt:
    ops

}

Try it yourself to see. If you run into wall by implementing it, fellow stackoverflow users, including myself would be pleased to help. But you need to try first.

Cheers.

Alp
  • 3,027
  • 1
  • 13
  • 28