I'm getting a "Property 'InnerText' is WriteOnly" error when trying to read an attribute value
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<products>
<product ID="11837">
<price currency="EUR">75.29</price>
<properties>
<property name="brand">
<value></value>
</property>
</properties>
<variations/>
</product>
</products>
To extract the price I do:
node.SelectSingleNode("price").InnerText
which returns "75.29"
But when I do:
node.Attributes("ID").InnerText
I get the error:
Property 'InnerText' is WriteOnly
I don't see any reason why it's write-only and don't know how I can change it so I can read the value.
It's a fact of the implementation of XmlAttribute
that it only supports writing to its InnerText
property. You don't "change it" so that you can read the value - you use the Value
property:
Gets or sets the value of the node.
Alternatively, you can access the value via InnerText
if you cast the XmlAttribute
as an XmlNode
(its base class).