Can't set xmlElement.Value Property


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Can't set xmlElement.Value Property

  1. #1
    Dan Thibodeaux Guest

    Can't set xmlElement.Value Property

    I keep getting the runtime message: An unhandled exception of type
    'System.InvalidOperationException' occurred in system.xml.dll. Additional
    information: Cannot set a value on node type: Element.

    Why doesn't this work? Am I missing something here?


    Dim Doc as New XmlDocument
    Dim Elem as XmlElement

    Elem = Doc.CreateElement("Employee")
    Elem.Value = "John Doe"



  2. #2
    Rob Teixeira Guest

    Re: Can't set xmlElement.Value Property



    Value applies to attributes, not elements.
    When you get to an element, you need to get it's child node of nodetype Text.
    That is the text content between the element start and end tag (if it exists).

    -Rob

    "Dan Thibodeaux" <danthi@houston.rr.com> wrote:
    >I keep getting the runtime message: An unhandled exception of type
    >'System.InvalidOperationException' occurred in system.xml.dll. Additional
    >information: Cannot set a value on node type: Element.
    >
    >Why doesn't this work? Am I missing something here?
    >
    >
    >Dim Doc as New XmlDocument
    >Dim Elem as XmlElement
    >
    >Elem = Doc.CreateElement("Employee")
    >Elem.Value = "John Doe"
    >
    >



  3. #3
    Dan Thibodeaux Guest

    Re: Can't set xmlElement.Value Property

    Are you sure about that? Aren't the attributes of the node stored in the
    Attribute property which is a XmlAttributeList collection?
    Can you give me a brief example?

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    news:3cda74b0$1@10.1.10.29...
    >
    >
    > Value applies to attributes, not elements.
    > When you get to an element, you need to get it's child node of nodetype

    Text.
    > That is the text content between the element start and end tag (if it

    exists).
    >
    > -Rob
    >
    > "Dan Thibodeaux" <danthi@houston.rr.com> wrote:
    > >I keep getting the runtime message: An unhandled exception of type
    > >'System.InvalidOperationException' occurred in system.xml.dll. Additional
    > >information: Cannot set a value on node type: Element.
    > >
    > >Why doesn't this work? Am I missing something here?
    > >
    > >
    > >Dim Doc as New XmlDocument
    > >Dim Elem as XmlElement
    > >
    > >Elem = Doc.CreateElement("Employee")
    > >Elem.Value = "John Doe"
    > >
    > >

    >




  4. #4
    Rob Teixeira Guest

    Re: Can't set xmlElement.Value Property


    "Dan Thibodeaux" <dant@rowancompanies.com> wrote:
    >Are you sure about that? Aren't the attributes of the node stored in the
    >Attribute property which is a XmlAttributeList collection?
    >Can you give me a brief example?
    >


    Yes, they are. What i meant to say is that what you are looking for is the
    XMLText node contained as child node of the Element node. The Value property,
    in this case applies to other node types, but not the XMLElement node. In
    other words, the text between the tags is a node itself, not the value of
    the element.

    Dim xd As XmlDocument = New XmlDocument()
    xd.LoadXml("<MyElement>This is some text</MyElement>")
    Dim el As XmlElement = xd.DocumentElement
    Dim tx As XmlText = el.FirstChild
    MsgBox(tx.Value)
    tx.Value = "This is some new text"
    MsgBox(el.FirstChild.Value)

    -Rob

  5. #5
    Trey Hutcheson Guest

    Re: Can't set xmlElement.Value Property


    Use the various text properties instead. For example, use InnterText to get/set
    the text of the element. You may use InnerXml to retrieve the actual XML
    markups of all the child nodes, or OuterXml to read the XML markups of its
    child nodes and of itself as well.

    InnerText is read/write. The Inner/OuterXml are both read-only, I think.

    trey


    "Dan Thibodeaux" <danthi@houston.rr.com> wrote:
    >I keep getting the runtime message: An unhandled exception of type
    >'System.InvalidOperationException' occurred in system.xml.dll. Additional
    >information: Cannot set a value on node type: Element.
    >
    >Why doesn't this work? Am I missing something here?
    >
    >
    >Dim Doc as New XmlDocument
    >Dim Elem as XmlElement
    >
    >Elem = Doc.CreateElement("Employee")
    >Elem.Value = "John Doe"
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center