-
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"
-
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"
>
>
-
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"
> >
> >
>
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks