In the following snippet, using XmlReader, when I encounter an element. I would like to read it as-is, including all attributes and namespace decoration in the element. Using the oXml.Name property, I am only able to get the tag name. Is there a function to get the tag itself?
oXml = XmlReader.Create(path, oXmlSettings) While oXml.Read() Select Case oXml.NodeType Case XmlNodeType.Element 'Read Element as-is If taglist.contains(oXml.Name) stringbuilder.Append(oXml.ReadOuterXml()) End If Case XmlNodeType.Text stringbuilder.Append(oXml.Value) End Select End While
I have tried oXml.ReadOuterXml() but it returns the element and its subcontent. That could be acceptable, but how do I fast forward my XmlReader to ignore subsequent XmlNodeType.Text and XmlNodeType.EndElement that will happen when the element I just got from ReadOuterXml has been parsed?
UPDATED: For the following snippet, loc1 is in taglist, so is written using ReadOuterXml, but the parser fails to get the following ‘!’ character.
<para> Test blabla <loc1 href='test'>complicated</loc1>! </para>
I haven’t tried it, but I wouldn’t expect that you’d have to fast forward the reader after calling ReadOuterXml. I’d expect the act of reading the outer XML to consume it.
Have you tried it?