Re: What up with this?
From: Derek Harmon (loresayer_at_msn.com)
Date: 01/02/05
- Next message: Jack Colletta: "Parse sub elements with namespace"
- Previous message: mailing_at_sunnybrisbane.com: "Re: "element is not declared" errors when validating xml from schema"
- In reply to: ByteMe: "What up with this?"
- Next in thread: Dino Chiesa [Microsoft]: "Re: What up with this?"
- Reply: Dino Chiesa [Microsoft]: "Re: What up with this?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 1 Jan 2005 19:01:04 -0500
"Anonymous" <ByteMe@discussions.microsoft.com> wrote in message news:C67757C5-973D-4821-9DD4-65F4AEC1D99C@microsoft.com...
> case XmlNodeType.Element:
> string test=SettingsReader.Value;
: :
> Why is the string test always empty?
The current node is an XML Element, and cannot have a value. There are two
good reasons for this.
1. It's consistent with the definition of an XML element in the W3C's DOM
Specification. Even though an XmlReader isn't a DOM implementation,
this consistency lets developers leverage their familiarity with comparable
XML API's when working with XmlReader.
2. The real reason is because XmlReader is a streaming reader, it hasn't
read the children of the XML element yet. SettingsReader can't know at
this point whether the XML element contains a whole subtree of other
elements, or one simple text child node. In order to determine this, you
must keep reading.
See the documentation of the HasValue property to determine which node
types can actually possess a Value,
What you probably mean to obtain in the string, test, is the value of the child
XML Text node of this element. The following technique shows one way
retrieve the 'text content' (in the XPath-sense) beneath an element, named
in some variable, strName (that's best fetched from the SettingsReader's
NameTable, although this example isn't that concerned with perf, e.g.,
the string concatenations instead of a formal StringBuilder.)
case XmlNodeType.Element:
if ( SettingsReader.LocalName == strName )
{
strTest = "";
flagCapture = true;
}
break;
case XmlNodeType.EndElement:
if ( SettingsReader.LocalName == strName )
{
RememberSetting( strName, strTest);
flagCapture = false;
}
case XmlNodeType.Text:
if ( flagCapture )
{
strTest += SettingsReader.Value;
}
Derek Harmon
- Next message: Jack Colletta: "Parse sub elements with namespace"
- Previous message: mailing_at_sunnybrisbane.com: "Re: "element is not declared" errors when validating xml from schema"
- In reply to: ByteMe: "What up with this?"
- Next in thread: Dino Chiesa [Microsoft]: "Re: What up with this?"
- Reply: Dino Chiesa [Microsoft]: "Re: What up with this?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|