Inserting Nodes between Nodes

Discussion in 'XML' started by cesarcesar, Jan 21, 2008.

  1. cesarcesar

    cesarcesar Guest

    Hi,

    XML novice here with another question. I need to add a XML node like,

    Code:
        <child01>
            <child02>
                <text></text>
                <image>image 1</image>
                <image>image 2</image>
            </child02>
        </child01>
    
    into this node between the ending </child01> and beginning <child01>
    of the


    Code:
        <child01>
            <child02>
                <text></text>
                <image>image 1</image>
                <image>image 2</image>
            </child02>
        </child01>
        <child01>
            <child02>
                <text></text>
                <image>image 1</image>
                <image>image 2</image>
            </child02>
        </child01>
    
    Does this make sense? I guess im looking for a way to say/do... make a
    new node with the following values and place it between these other
    two nodes.

    I still am learning XML but i think this can be done.
     
    cesarcesar, Jan 21, 2008
    #1
    1. Advertising

  2. cesarcesar

    cesarcesar Guest

    On Jan 21, 12:34 am, cesarcesar <> wrote:
    > Hi,
    >
    > XML novice here with another question. I need to add a XML node like,
    >
    >
    Code:
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    > 
    >
    > into this node between the ending </child01> and beginning <child01>
    > of the
    >
    >
    Code:
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    > 
    >
    > Does this make sense? I guess im looking for a way to say/do... make a
    > new node with the following values and place it between these other
    > two nodes.
    >
    > I still am learning XML but i think this can be done.


    woops sorry, my 2nd XML is wrong. here is the correct.

    Code:
    <child01>
    	<child02>
    		<text></text>
    		<image>image 1</image>
    		<image>image 2</image>
    	</child02>
    	<child02>
    		<text></text>
    		<image>image 1</image>
    		<image>image 2</image>
    	</child02>
    </child01>
    <child01>
    	<child02>
    		<text></text>
    		<image>image 1</image>
    		<image>image 2</image>
    	</child02>
    	<child02>
    		<text></text>
    		<image>image 1</image>
    		<image>image 2</image>
    	</child02>
    </child01>
    
     
    cesarcesar, Jan 21, 2008
    #2
    1. Advertising

  3. cesarcesar

    cesarcesar Guest

    On Jan 21, 12:34 am, cesarcesar <> wrote:
    > Hi,
    >
    > XML novice here with another question. I need to add a XML node like,
    >
    >
    Code:
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    > 
    >
    > into this node between the ending </child01> and beginning <child01>
    > of the
    >
    >
    Code:
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    >     <child01>
    >         <child02>
    >             <text></text>
    >             <image>image 1</image>
    >             <image>image 2</image>
    >         </child02>
    >     </child01>
    > 
    >
    > Does this make sense? I guess im looking for a way to say/do... make a
    > new node with the following values and place it between these other
    > two nodes.
    >
    > I still am learning XML but i think this can be done.


    one other thing... i want to do this in PHP if possible, but other
    languages are ok.
     
    cesarcesar, Jan 21, 2008
    #3
  4. cesarcesar wrote:

    > <child01>
    > <child02>
    > <text></text>
    > <image>image 1</image>
    > <image>image 2</image>
    > </child02>
    > </child01>
    > <child01>
    > <child02>
    > <text></text>
    > <image>image 1</image>
    > <image>image 2</image>
    > </child02>
    > </child01>


    That snippet is not a well-formed document. As most APIs do only process
    well-formed documents it is not necessarily possible to process the
    above input and change it.
    And you have not given us any indication of what programming language
    and what API you want to use.




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 22, 2008
    #4
  5. cesarcesar wrote:
    > one other thing... i want to do this in PHP if possible, but other
    > languages are ok.


    I don't know PHP, but the standard APIs would be DOM or SAX. For a
    beginner, this task is easier using the DOM tree -- load the document,
    find the point where you want to insert the data, create the node tree
    you want to insert, insert it, write the DOM out as your new document.
    See any good DOM tutorial for details.

    With SAX, it's a bit more complicated since you need to code up a state
    machine of some sort that recognizes when you've reached the appropriate
    point in the document and outputs the new content. Again, lots of
    tutorials exist showing the general outlines of this task.

    I normally refer folks to http://www.ibm.com/xml for educational
    documents. Other article/tutorial repositiories also exist, or you can
    go looking for hardcopy books on programming with XML.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 22, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. indo3
    Replies:
    0
    Views:
    464
    indo3
    Jul 3, 2004
  2. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    437
    Patrick TJ McPhee
    Jun 17, 2004
  3. indo3
    Replies:
    0
    Views:
    425
    indo3
    Jul 2, 2004
  4. Blondeamon

    Problem with inserting nodes on Binary trees

    Blondeamon, Dec 24, 2007, in forum: C Programming
    Replies:
    1
    Views:
    247
    Nikos Chantziaras
    Dec 24, 2007
  5. Blondeamon
    Replies:
    1
    Views:
    303
    Nikos Chantziaras
    Dec 24, 2007
Loading...

Share This Page