Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Create and Update the attributes of XML file

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-04-2009
Member
 
Join Date: Apr 2009
Posts: 51
Create and Update the attributes of XML file
  

Hello world,

I have been practising for XML and have written the code in file like this:

Code:
 <listof> 
  <project name= "Projet1" type= "Externe"> 
  <source name= "Nom1" value= "Valeur1" created= "28/04/09"> 
  <source name= "Nom2" value= "Valeur2" created= "28/05/09"> 
  <source name= "Nom3" value= "Valeur3" created= "20/04/09"> 
  </ project> 
  </ listof>
But I would succeed in making 2 things:
- Insert a new line type

Code:
<source name= "Nom4" value= "Valeur4" created= "20/04/09">
after the line name = "Nom3.

Update the values of an existing line. Example: replace the value "value2" with "NouvelleValeur2.

Do you have examples of code to manipulate, create and update these attributes? What is the best way to proceed?

Thank you for your help.

Reply With Quote
  #2  
Old 30-04-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: Create and Update the attributes of XML file

Hello,

I'd hate to say this, but first, is it possible for you to use a different language. but one thing is clear that VB.Net has excellent XML parsing capabilities. Java, on the other hand, is very inadequate. The following XML block will add or update entries in the appSettings section of web.config. If elements with the same value in the key attribute exists the value attributes are updated,otherwise new elements are added.

Code:
<addBlock path="/configuration">
  <appSettings>
    <add key="companyName" value="EPiServer" __keyAttributes="key" />
    <add key="country" value="sweden" __keyAttributes="key" __firstChild="true" />
  </appSettings>
</addBlock>
Reply With Quote
  #3  
Old 30-04-2009
Member
 
Join Date: Apr 2009
Posts: 51
Re: Create and Update the attributes of XML file

Thanks for your example, actually yes I already use the XmlDocument class to delete a line, for example, or read the contents of the XML file.
But I can not find an example to update and insert.
Thank you.
Reply With Quote
  #4  
Old 30-04-2009
Member
 
Join Date: Jan 2009
Posts: 140
Re: Create and Update the attributes of XML file

If you really want to change a value of an attribute to simply access the attribute and change its value you can use XPath queries, or directly via the XmlDocument if the structure is relatively simple.

To insert a line just create a new element (see the different ways ... Create the XmlDocument class), to have a benchmark against which we will add the item and add it (see methods InsertBefore, InsertAfter, appendChild, of class PrependChild XmlNode for example)
Hope this helps you.
Reply With Quote
  #5  
Old 30-04-2009
Member
 
Join Date: Jan 2009
Posts: 143
Re: Create and Update the attributes of XML file

to add a line like source, there must be something in this genre

Code:
 Sunday ParentNode As XmlNode = MyDocument. GetElementsByTagName ( "project"). Item (0) 
          Sunday EnfantNode As XmlElement = Report. CreateElement ( "source") 
          ParentNode. PrependChild (EnfantNode)
To manage the item number you will have to prepend before and then initialize the values of attributes.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Create and Update the attributes of XML file"
Thread Thread Starter Forum Replies Last Post
How to create and set values for newly created attributes in active directory m v ramana Active Directory 1 18-05-2011 01:19 AM
Display of .msg file attributes in Explorer Obama P Windows Software 4 13-08-2010 10:19 PM
Cannot decrypt a file - error occurred applying attributes to file kEyURi Windows XP Support 1 20-04-2010 08:04 PM
how to update or modify AD properties attributes vivekmohan Software Development 2 02-09-2009 09:01 PM
Script to Update user attributes in AD Fahad Active Directory 3 29-05-2009 02:44 AM


All times are GMT +5.5. The time now is 02:16 PM.