Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 0 down vote accepted

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .