1

Possible Duplicate:
Add an attribute with static value with xslt

I have an XML file which I need to modify.

For example:
Say my XML has a form tag

<FORM name=""></FORM>

Now say I want to put some extra info to this tag like

frame="frmName" frameby="name"

Expected result of running batch file OR some XSLT

<FORM name="" frame="frmName" frameby="name" ></FORM>

How can I do it using batch file?
I am just a beginner so please try to be simple.

Thank you all

Community
  • 1
  • 1
EMM
  • 1,812
  • 8
  • 36
  • 58
  • http://stackoverflow.com/questions/5477209/how-to-replace-text-in-text-file-using-bat-file-script http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-enviro – Yarg Sep 16 '11 at 05:13
  • Do you always expect
    in the input xml?
    – Sergey Podobry Sep 16 '11 at 05:17
  • @Sergius No it can be any tag. I wrote FORM tag just for an example. – EMM Sep 16 '11 at 05:49

1 Answers1

2

Have you considered using XSLT to modify the XML, as further explained here

EDIT

xlst solution

<xsl:template match="FORM">
 <xsl:copy>
   <xsl:attribute name="name">frmName</xsl:attribute>
   <xsl:apply-templates select="node()|@*/>
  </xsl:copy>
 </xsl:template>
Community
  • 1
  • 1
bbaja42
  • 2,099
  • 18
  • 34
  • yes I would like to use XSLT.+1 for your answer,let me test it before I could accept it. – EMM Sep 16 '11 at 06:05
  • I don't know what is going on here, could you please provide some simple answer specific to my question. – EMM Sep 21 '11 at 11:48
  • @mohit Could you elaborate? The answer give details how to solve the problem using different tool (XSLT vs batch file). How can I be more specific? – bbaja42 Sep 21 '11 at 13:34
  • This is not working at all, it shows an exception on my browser saying "not well formed XML".I don't know what I am missing.Also I am trying to achieve something slightly different, please have a look at the question. – EMM Sep 22 '11 at 05:59
  • It would help if you would include the whole xml (the one the shows not well formed XML). – bbaja42 Sep 22 '11 at 07:24
  • Hi, I have resolved that, I was missing a closing tag.But I am still looking for my actual problem.How to add a new attribute to my existing tag while displaying the previous attributes ? – EMM Sep 22 '11 at 08:41
  • this is what your code produces.
    This is what I need. :(
    – EMM Sep 23 '11 at 05:51
  • Apply it again with different attribute name and value. – bbaja42 Sep 23 '11 at 07:30
  • Hi, it worked but it removed all other nodes present in my XML, but I guess I can handle that. Many thanks. – EMM Sep 23 '11 at 08:21