Inserting Nodes between Nodes

C

cesarcesar

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.
 
C

cesarcesar

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>
 
C

cesarcesar

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.
 
M

Martin Honnen

cesarcesar said:
<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.
 
J

Joseph Kesselman

cesarcesar said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top