Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Differently another way to set value for element in XML?

Differently another way to set value for element in XML?

Scheduled Pinned Locked Moved C#
xmltutorialquestionannouncementlearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhatvhm
    wrote on last edited by
    #1

    Hi , Recently i tried to get an xml file that contains many element with no values and set their values.

    <Book>
    <Auther>
    <Name></Name>
    <Age></Age>
    </Auther>
    <Publicity>
    <Year></Year>
    </Publicity>
    </Book>

    this xml Element elements has no values and i want to set their values and save the xml string to file.I used to ... mNodeChild = mDoc.CreateElement("Name");``mNodeChild.Value="John";. Although, this line code is correct syntax. But when this program write to XML file that is message announcement {Cannot set a value on node type 'Element'} do someone knows how to do it?

    G 1 Reply Last reply
    0
    • N nhatvhm

      Hi , Recently i tried to get an xml file that contains many element with no values and set their values.

      <Book>
      <Auther>
      <Name></Name>
      <Age></Age>
      </Auther>
      <Publicity>
      <Year></Year>
      </Publicity>
      </Book>

      this xml Element elements has no values and i want to set their values and save the xml string to file.I used to ... mNodeChild = mDoc.CreateElement("Name");``mNodeChild.Value="John";. Although, this line code is correct syntax. But when this program write to XML file that is message announcement {Cannot set a value on node type 'Element'} do someone knows how to do it?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      An xml element doesn't have a value. Use the InnerText property to set the content of the element.

      Despite everything, the person most likely to be fooling you next is yourself.

      N 1 Reply Last reply
      0
      • G Guffa

        An xml element doesn't have a value. Use the InnerText property to set the content of the element.

        Despite everything, the person most likely to be fooling you next is yourself.

        N Offline
        N Offline
        nhatvhm
        wrote on last edited by
        #3

        Great! Thank you so much :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups