samedi 25 avril 2015

Large XML file - wrap elements inside tags using XSLT or by manipulating the XML as String?


I have a fairly large XML file, around 3-4 MB and I need to wrap certain elements inside tags. My Xml has the following structure:

<body>
    <p></p>
    <p>
        <sectPr></sectPr>
    </p>
    <p></p>
    <p></p>
    <tbl></tbl>
    <p>
        <sectPr></sectPr>
    </p>
</body>

Of course, all the p and tbl elements will repeat themselves inside the body until the end of the file (also each of the elements presented above will have children - I just took them out for the sake of simplicity). As an estimate, I will have around 70 elements containing sectPr inside body, not necessarily in the order I described above.

What I would like to do, is to wrap all the elements that are starting from an element containing sectPr to the next element containing sectPr into another tag. As a result, my XML should look like this:

<body>
    <p></p>
    <myTag>
        <p>
            <sectPr></sectPr>
        </p>
        <p></p>
        <p></p>
        <tbl></tbl>
    </myTag>
    <myTag>
        <p>
            <sectPr></sectPr>
        </p>
    </myTag> 
</body>

Also, another requirement is that the operation must be performed under 40 seconds.

My question is: Do you think is possible to achieve this result using XSLT and if this is the case could please provide a short description on how can I do it, or do you think is better to read the XML file as String and then add the tags by manipulating the string?

Also, as programming language, I am using Visual Basic.

Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire