Jump to content

Inserting Nodes between Nodes


cesarcesar

Recommended Posts

Hi,

 

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

 

    <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

 

 

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

Link to comment
https://forums.phpfreaks.com/topic/87015-inserting-nodes-between-nodes/
Share on other sites

Hi,

 

Referring you code .

 

what is the need of <child02> how it differe if the <text><image> falls in <child01> ????

this won't be considered as proper XML.what you can do is

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

This make some sense i suppose.As i am not aware what you are trying to do this may not be the best XML format but this will be lighter and faster to parse compare to the previous.

 

Regards

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

 

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

one other thing... i want to do this in PHP if possible, but other languages are ok.

 

Dear, you can to XML creation and parsing of it in PHP.This language has potential to do it faster and better.But again i would like to check your second XML

if <child01> is not similar with second occurance of <child01> then its okie but if it is similart then create only one xml <tag> for it take example

 

hild01>

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

<child02> it sud not be child01

              <child022>

<text></text>

<image>image 1</image>

<image>image 2</image>

</child022>

<child022>

<text></text>

<image>image 1</image>

<image>image 2</image>

</child022>

</child02>

 

Regards

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.