LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert nodes at a specific location in Xml

Solved!
Go to solution

Hello All, 

i am working with this big xml.I am reading a part of it and editing it and writing back . While Writing back I am deleting the existing nodes and build up new nodes and writing them . My problem is when i am writing the new nodes are being inserted at the bottom i want to insert them at the original place

Eg:-

Original

<Main>

<Machine NUM=1/>

<Machine NUM=2/>

<Material NUM=1/>

<Material NUM=2/>

</Main>

What i get after writining back

<Main>

 

<Material NUM=1/>

<Material NUM=2/>

<Machine NUM=1/>

<Machine NUM=2/>

<Machine NUM=3/>

</Main>

 

What i want

<Main>

<Machine NUM=1/>

<Machine NUM=2/>

<Machine NUM=3/>

<Material NUM=1/>

<Material NUM=2/>

</Main>

0 Kudos
Message 1 of 8
(2,679 Views)

It is extremely difficult to see what you are doing from the partial Snippet you attached.  There are broken wires, data structures (like Nodes) that I don't understand, etc.

 

I think you have the "wrong algorithm".  Here (without knowing the details of your data structure, and not knowing how you make decisions) is one possibility:

  1. Do a pass through the data.  As you do, create a "replacement" list that says something to the effect of "Replace Node X with this Node".
  2. Now do a second pass through the data.  If a Node is not on your Replacement list, write it out to the "New List".  Otherwise, write out the appropriate Replacement Node.
  3. When you are done, you will have used all of the elements in the Replacement list and will have a New List in the same order as the Original List (which can be deleted, if you wish).

Bob Schor

0 Kudos
Message 2 of 8
(2,623 Views)

You're using the Append Child method, this is what this method is used for (add the new child at the end). Use Insert Before method instead with <Material NUM=1/> as the reference node.

 

Ben64

Message 3 of 8
(2,602 Views)

Hallo bob schor

soory i didnt think the rest of the vi would help in knowing the data structure as you can see i am sending a 2d array and a 1 d array and making a cluster5 out of them toi place them in required format. the xml format is a bit complex .

its like this

<Main>

<Machine1 Attr1 Attr2 ...>

<Node1 Attr1 Attr2../>

<Node2 Attr1 Attr2../>

</Machine1>

 

<Machine2 Attr1 Attr2 ...>

<Node1 Attr1 Attr2../>

<Node2 Attr1 Attr2../>

</Machine2>

...

Smae for material

</Main>.

Hallo Ben 64,

I realise that but I didnt find any examples with insert method Can you please provide me with some reference 

Thanks,

0 Kudos
Message 4 of 8
(2,579 Views)

@anilkumarmuppirala18 wrote:

Hallo bob schor

soory i didnt think the rest of the vi would help in knowing the data structure as you can see i am sending a 2d array and a 1 d array and making a cluster5 out of them toi place them in required format. the xml format is a bit complex .


I'm sorry, but you "Just Don't Get It" (I probably wasn't sufficiently clear, but I'll explain, here).  You say "as you can see", but that's exactly the point, I cannot "see".  What you attached was a picture where everything was very tiny, impossible (for me) to see without doing a lot of unnecessary work, while if you attached your LabVIEW VI, I would just open LabVIEW, see all the VIs and wires at "normal size", easily visible, and if I wanted to "simplify" it or straighten out the wires, I could do that.  I could also test it, be sure I understood how it worked, and possibly been able to actually suggest code changes.

 

But OK, I'll let someone else strain their eyes trying to help you.  I was just hoping you were willing to make a small effort to help me to help you ...

 

Bob Schor

0 Kudos
Message 5 of 8
(2,566 Views)

hello bob i am attaching the vi

0 Kudos
Message 6 of 8
(2,562 Views)
Solution
Accepted by topic author anilkumarmuppirala18

Modify your code as follow, I didn't try it (you didn't provided the xml file) but it should be close to what you want.

Insert before.png

 

Ben64

Message 7 of 8
(2,553 Views)

Thank you very much ben that worked like a charm . sorry i could not share the xml as i am not allowed to share it . Thnaks for you help   O:-)

0 Kudos
Message 8 of 8
(2,535 Views)