Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some xml that looks like this in each report:

Header
Cell
/Cell
Cell
/Cell
...
/Header

In each cell I need to add:

                <property name="borderBottomColor">#E1E1E1</property>
                <property name="borderBottomStyle">solid</property>
                <property name="borderBottomWidth">thin</property>

This will take me about a week to do manually.

Is there a tool that could do this?

Thanks

share|improve this question
    
What about using your favourite editor (vim, emacs, …) and a custom macro? –  Marco Sep 11 '12 at 15:04

2 Answers 2

You can try XMLStarlet - an open source, command-line XML editor.

It allows you for example to add or update nodes in an XML document. Which nodes are updated can be specified by an XPath expression.

share|improve this answer

It's hard to give an exact answer without actual sample XML input (and a full output example), but you could use XSLT

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Cell">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>           
            <property name="borderBottomColor">#E1E1E1</property>
            <property name="borderBottomStyle">solid</property>
            <property name="borderBottomWidth">thin</property>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

You could run this with Xalan or Saxon from the command line.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.