PDA

View Full Version : Using datapointer to edit XML


jpan
05-03-2004, 08:08 AM
Hi,

I have an XML that's loaded through HTTP into a dataset, and the XML looks like


<XMLMessage>
<Units>
<Record>Data 1</Record>
<Record>Data 2</Record>
<Record>Data 3</Record>
</Units>
</XMLMessage>


Now, I want to add a node into here, and the result XML should look like:


<XMLMessage>
<Units>
<Record>Data 1</Record>
<Record>Data 2</Record>
<Record>Data 3</Record>
</Units>

<!-- NEW DATA HERE -->
<AdditionalList />

</XMLMessage>


The reason for this is because, later on in the processing, I want to add nodes into "AdditionalList", such that the XML will look like this:


<XMLMessage>
<Units>
<Record>Data 1</Record>
<Record>Data 2</Record>
<Record>Data 3</Record>
</Units>

<!-- NEW DATA HERE -->
<AdditionalList />
<Record>Additional 1</Record>
<Record>Additional 2</Record>
<Record>Additional 3</Record>
</AdditionalList>

</XMLMessage>


The node "AdditionalList" is not in the source http XML because of some other problems and cannot be added easily, which is why I'm doing it in the client.

The code I use to add "AdditionalList" node is:

dataPointer.setXPath( "RemoteMessage:/XMLMessage");
dataPointer.addNode("AdditionalList", "");


And then to add the children nodes to it, I use:


dataPointer.setXPath( "RemoteMessage:/XMLMessage/AdditionalList");
dataPointer.addNode("Record", dataString);


This doesn't work properly, as I noticed an additional child-node in "AdditionalList". My assumption is that the original text node added to AdditionalList is getting counted.

How can I deal with this? I really only want to put in a place-holder node in the XML that will allow me to add/remove child-nodes into the place-holder... OR, is there a better way to accomplish what I need to do??

Thank you!

jpan
05-03-2004, 08:45 AM
Never mind.

Sorry about the stupid post. I did this instead


dataPointer.addNode("AdditionalList", null);


And everything works now... sorry!

antun
05-03-2004, 03:04 PM
FYI, there's another way of tinkering with data nodes. Each datapointer has a "p" attribute that is a pointer to the LzDataNode instance that the datapointer points to. Check out the examples on the LzDataElement docs page:

http://www.laszlosystems.com/lps-2.1/docs/lzx-reference/?lzdatanode.html

It's a more object-orientated approach, and you might find it less cumbersome than calling addNode on the datapointer.

-Antun