We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › delete an entry in a xml file
Page Index Toggle Pages: 1
delete an entry in a xml file (Read 1023 times)
delete an entry in a xml file
Jan 10th, 2010, 8:08am
 
hey guys,

i'm using the proxml library and
i have an xml file structured like this: (named positions.xml)

<?xml version="1.0" encoding="ISO-8859-1"?>
<positions>
 <type>
   <dataType v1="200" v2="12" v3="10"/>
 </type>
 <type>
   <dataType v1="150" v2="12" v3="20"/>
 </type>
 <type>
   <dataType v1="100" v2="12" v3="30"/>
 </type>
</positions>

inside of my processing sketch i now want to delete the first entry of the xml-file when pressing the "x"-key.
if i consider this right i have to use a for-loop to go through all entries and then delete the first one.
but which code do i have to use to delete an xml entry?! and how do i go through an xml file by using a for-loop?

thanks for your help in advance !!!!!!

Re: delete an entry in a xml file
Reply #1 - Jan 11th, 2010, 2:49pm
 
i first tried to work on the for-loop to go through the xml-file.
i tried it this way but i don't think this is working correctly. and still i don't have any idea how to delete entries in an existing xml - file?

Code:
void xmlEvent(XMLElement element){

proxml.XMLElement[] data = element.getChildren();

for (int i = 0; i < data;i++)
{
proxml.XMLElement data = data[i];
proxml.XMLElement param = data.getChild(0);
//println(param.getName());
if (!param.getName().equals("dataType"))
continue; // Ignore unknown child
// int value1 = param.getIntAttribute("v1");
int value1 = param.getIntAttribute ("v1");
int value2 = param.getIntAttribute("v2");
int value3 = param.getIntAttribute("v3");



}

DatenXML = element;
initDaten();
}
Re: delete an entry in a xml file
Reply #2 - Jan 12th, 2010, 2:29am
 
I can be wrong, but I believe the way to do that is to load the XML file in memory, with whatever storage way you care to do (we don't have a Dom, have we?), manipulate the data the way you want, then save back the XML file.
Page Index Toggle Pages: 1