Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2005, 11:47 PM
Authorized User
 
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Manipulating the XML File

Hi..
Can anyone tell me how to do the following.
I m totally new to XML..

There is one XML file(already existing)
I want to make the following changes.
a) Uncomment one line
<main1>

</main1>
<main2>
</main2>

I want it like this ::<abc prop1="1" prop2="2"/>

b) Change the property of one of the node.

<abc prop1="1" prop2="2"/>
I want it like this::<abc prop1="3" prop2="2"/>



Please help me out.
it is urgent..
Thanks

Jyoti
 
Old January 11th, 2005, 05:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think this is very difficult. Here is a stylesheet that will uncomment all comments in a rather "hackish" way that works with msxml2:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="comment()">
    <xsl:value-of disable-output-escaping="yes" select="normalize-space(.)"/>
  </xsl:template>
</xsl:stylesheet>
To do this properly you'd have to specify a bit more:
How do you decide which commments to remove? Is it all or those matching a certain pattern?

What are the rules for changing the attributes?

If this is just a one-off stylesheet that needs to be run against many files and there is just one comment that needs to be removed and the contents changed then:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="comment()">
    <abc prop1="3" prop2="2"/>
  </xsl:template>
</xsl:stylesheet>
would do it.


--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.