Results 1 to 5 of 5

Thread: Create and Update the attributes of XML file

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

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

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

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

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

Similar Threads

  1. Replies: 1
    Last Post: 18-05-2011, 01:19 AM
  2. Display of .msg file attributes in Explorer
    By Obama P in forum Windows Software
    Replies: 4
    Last Post: 13-08-2010, 10:19 PM
  3. Replies: 1
    Last Post: 20-04-2010, 08:04 PM
  4. how to update or modify AD properties attributes
    By vivekmohan in forum Software Development
    Replies: 2
    Last Post: 02-09-2009, 09:01 PM
  5. Script to Update user attributes in AD
    By Fahad in forum Active Directory
    Replies: 3
    Last Post: 29-05-2009, 02:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,570,881.31893 seconds with 17 queries