Groups | Blog | Home
all groups > dotnet xml > january 2006 >

dotnet xml : XmlTextReader-derived class - overrides not being called



Ian Harding
1/11/2006 4:49:10 PM
I have a class derived from XmlTextReader. It implements the following
methods:
public override void ReadEndElement()
public override void ReadStartElement()
public override string ReadString()
public override bool Read()

When the class is used to read a document, the Read override is called
many times and I can see the document contents being stepped through
using base.LocalName etc. What I don't understand is that the other
three overrides are never called. Samples I've found on Google seem to
indicate that all ReadXXX methods are called when a relevant document
item is encountered but that isn't happening in this case.

My aim is to replace an attribute value on all occurances of a specific
element. I can add code into the Read() override to identify when the
reader is processing that element, but need to override the behaviour of
ReadString() so I can substitute the new attribute value.

Thanks,
Naraendira Kuma R.R.
1/11/2006 11:22:18 PM
Seems like you could accomplish the same goal, easily using XSLT without
using XmlTextReader.

--
Naraendira Kumar R.R.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
[quoted text, click to view]

Ian Harding
1/12/2006 10:16:00 AM
[quoted text, click to view]

I was trying to keep overhead to a minimum. What I've read indicates
that reading a document with an XmlReader should be more efficient that
XSLT in this case. The XML document arrives in a string, the
XmlTextReader isolates one part of the document (an ADO Recordset) into
another string, then the Recordset is de-serialized from the XML.

On the other hand, if there's no way of substituting an attribute value
using an XmlReader, I might have to go the XSLT route.

Thanks,
Chris Lovett
1/15/2006 1:14:06 AM
Yes, XmlReader will be more efficient. Attributes are read by the
XmlDocument via MoveToNextAttribute, then each attribute value is acessed
via the Value property, so it's probably the Value property that you'll need
to override, and perhaps MoveToNextAttribute() also, to remember which
attribute you are positioned on.

[quoted text, click to view]

AddThis Social Bookmark Button