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 March 22nd, 2004, 06:24 AM
sai sai is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to add or delete a node from an xml documnet

hai friends,

how to add or delete a node from an xml document ,using only xpath query which is called by xml DOM Interface method

here i am also supplying 2 files which may help u to understand in solving my problem.

file 1

<?xml version="1.0" encoding="UTF-8"?>

<book>
    <category>
        <name>Category1</name>
        <group>
            <name>Group1</name>
            <bookname>
                <name>book1</name>
            </bookname>
            <bookname>
                <name>book2</name>
            </bookname>
        </group>
        <group>
            <name>Group2</name>
            <bookname>
                <name>book3</name>
            </bookname>
            <bookname>
                <name>book4</name>
            </bookname>
        </group>
    </category>
    <category>
        <name>Category2</name>
        <group>
            <name>Group1</name>
            <bookname>
                <name>book1</name>
            </bookname>
            <bookname>
                <name>book2</name>
            </bookname>
            <bookname>
                <name>book3</name>
            </bookname>
        </group>
        <group>
            <name>Group2</name>
            <bookname>
                <name>book4</name>
            </bookname>
            <bookname>
                <name>book5</name>
            </bookname>
            <bookname>
                <name>book6</name>
            </bookname>
            <bookname>
                <name>book7</name>
            </bookname>
        </group>
    </category>
</book>

we should get the output as this file 2
file 2

<?xml version="1.0" encoding="UTF-8"?>

<book>
    <category>
        <name>Category1</name>
        <group>
            <name>Group1</name>
            <bookname>
                <name>book1</name>
            </bookname>
            <bookname>
                <name>book2</name>
            </bookname>
        </group>
        <group>
            <name>Group2</name>
            <bookname>
                <name>book3</name>
            </bookname>
            <bookname>
                <name>book4</name>
            </bookname>
        </group>
    </category>
    <category>
        <name>Category2</name>
        <group>
            <name>Group1</name>
            <bookname>
                <name>book1</name>
            </bookname>
            <bookname>
                <name>book2</name>
            </bookname>
            <bookname>
                <name>book3</name>
            </bookname>
        </group>
        <group>
            <name>Group2</name>
            <bookname>
                <name>book4</name>
            </bookname>
            <bookname>
                <name>book5</name>
            </bookname>
            <bookname>
                <name>book6</name>
            </bookname>
            <bookname>
                <name>book7</name>
            </bookname>
        </group>
        <group>
            <name>Group3</name>
            <bookname>
                <name>book8</name>
            </bookname>
            <bookname>
                <name>book9</name>
            </bookname>
            <bookname>
                <name>book10</name>
            </bookname>
            <bookname>
                <name>book11</name>
            </bookname>
        </group>
    </category>
</book>


regards
sai

 
Old March 22nd, 2004, 06:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What information do you have so you know what to add to file one? For instance, will you have a group number and a list of book names? How do you know which nodes to remove? Whole groups or just individual books?
You cannot do this with just XPath query, this can only locate nodes, you will either need to do an XSLT transformation or use the DOM to append and remove nodes.

Joe (MVP - xml)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Node add/delete aintvoguish XSLT 2 December 20th, 2007 03:01 AM
How to delete a xml node with all attributes and s vishnu108mishra XML 2 November 14th, 2007 04:19 AM
delete XML node in Perl crmpicco Perl 4 November 28th, 2006 12:12 PM
delete XML node from JavaScript - not child crmpicco Javascript How-To 1 April 27th, 2006 11:42 AM
delete XML node with javascript crmpicco Javascript How-To 5 April 6th, 2006 03:35 AM





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