mardi 4 août 2015

best way to compare xml data's and present that to user as HTML

Consider the following two different xml based result/response, all follow same xsd in general

    xml1: 
    <student name="1" rollNo="1">
        <result>
            <subject name="lang" marks=90/>
            <subject name="science" marks=80/>
            <subject name="maths" marks=95/>
        </result>
    </student>

    xml2: 
    <student name="2" rollNo="2">
        <result>
            <subject name="lang" marks=100/>
            <subject name="science" marks=90/>
            <subject name="maths" marks=90/>
        </result>
    </student>

    Expected Comparison HTML:

    Students Result:
    ------------------------------------
            |        Subjects           |
    Roll No |---------------------------
            | lang  | science   | maths |   
    -------------------------------------
    1       | 90   |    80      | 95    |   
    2       | 100  |    90      | 90    |
    -------------------------------------

Also consider the future cases like, if the xml evolves with more added details

    <student name="1" rollNo="1">
        <result>
            <subject name="lang">
                <internal =50>
                <external =40>
            </subject>
            ....
        </result>
    </student>

then the table should also presented like

    ----------------------------------------------
            |        Subjects                    |
    Roll No |-------------------------------------
            | lang      | science    | maths     |  
            --------------------------------------
            | int | ext |  int | ext | int | ext |
    ----------------------------------------------
     1      | 50 |  40 |   50  | 30  |  50 |  45 |      
     2      | 50 |  30 |   50  | 45  |  50 |  30 |
    ----------------------------------------------

The same logic, should also be able to compare some other group of xml's, they follow their own kind of xsd's

Consider other kind for ex:

<employee name="1" rollNo="1">  
    <appearance height="" weight=90 gender=""/>
    <department name="HR" role="" experience=""/>
</employee>

<employee name="1" rollNo="1">  
    <appearance height="" weight=90 gender=""/>
    <department name="HR" role="" experience=""/>
</employee>

Expected Comparison HTML:

Employee Comparison:

--------------------------------------------------------
        |        Appearance         |   Department      |
Roll No |-----------------------------------------------|
        | height | weight |  gender |   name | role     |
---------------------------------------------------------
1       |                                               |       
---------------------------------------------------------
2       |                                               |
---------------------------------------------------------

Is there any best/recommended/generic approach to achieve this? Tools? thrid-parties? API's? In terms of performance? maintenance?

Right now, to achieve this, what I have done is step1: append all xml under a single parent [ex: repeating student nodes under students] step2: Write customized xslt for each type of xsd family and digest against the concated xml results and make HTML out of it.

Tools: java - xsd's, xml parsers, xslt, HTML

As per my project req, I expect atleast 30 kind of xsd families, and the comparison framework should support all of them with generic impl.

Any recommendation would be really saving my days :)

Aucun commentaire:

Enregistrer un commentaire