473,513 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No XmlNodeType for an EmptyElement with Attribute

I have a MemoryStream of XML in which I wish to strip out the
namespaces and some other attributes and then write this revised Stream
to a new MemoryStream

Everything works grand in the code below expect when myReader comes
across an element like:
<xxx id="1"/>
i.e. an empty element with attributes

I think myReader.IsEmptyElement is no use in this instance as there is
an attribute in the "EmptyElement"

Heres the guts of the code:
************************************************** ********************
Dim myReader As New XmlTextReader(p_Stream)
'Where p_Stream is the original MemoryStream of XML
'Where outputStream is the target MemoryStream of XML
Dim myWriter As New XmlTextWriter(outputStream, Encoding.UTF8)

While myReader.Read
Select Case myReader.NodeType
Case XmlNodeType.Element

' in here i check if there are attributes
' & strip out the ones i dont wont using
' myReader.MoveToNextAttribute &
' WriteAttributeString where appropriate.
' <xxx id="1"/> is caught in here
' but the associated end element is
' never moved to by myReader.Read
' - so eventually the xml is badly formed

Case XmlNodeType.EndElement
myWriter.WriteEndElement()
Case XmlNodeType.Text
myWriter.WriteString(myReader.Value)
Case XmlNodeType.SignificantWhitespace
myWriter.WriteString(myReader.Value)
Case XmlNodeType.XmlDeclaration
myWriter.WriteStartDocument()
Case Else
'Do nothing
End Select
End While

************************************************** ********************

Perhaps there is a better way to go about this altogether.
I'm open to all options.

Dickster

Nov 12 '05 #1
2 1541


dickster wrote:

I think myReader.IsEmptyElement is no use in this instance as there is
an attribute in the "EmptyElement"

Heres the guts of the code:
************************************************** ********************
Dim myReader As New XmlTextReader(p_Stream)
'Where p_Stream is the original MemoryStream of XML
'Where outputStream is the target MemoryStream of XML
Dim myWriter As New XmlTextWriter(outputStream, Encoding.UTF8)

While myReader.Read
Select Case myReader.NodeType
Case XmlNodeType.Element

You need to check
myReader.IsEmptyElement
here as the markup <xxx id="1"/> should give you true in that case while
the reader will not give you an EndElement for that markup.
Case XmlNodeType.EndElement
myWriter.WriteEndElement()

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thanks Again Martin.. Heres my working code
================================================== ==========

While myReader.Read

If myReader.IsEmptyElement() Then
myWriter.WriteStartElement(myReader.Name)

' Handle attributes

myWriter.WriteEndElement()

Else
Select Case myReader.NodeType
Case XmlNodeType.Element

myWriter.WriteStartElement(myReader.Name)
' Handle attributes

Case XmlNodeType.EndElement
myWriter.WriteEndElement()
Case XmlNodeType.Text
myWriter.WriteString(myReader.Value)
Case XmlNodeType.SignificantWhitespace
myWriter.WriteString(myReader.Value)
Case XmlNodeType.XmlDeclaration
myWriter.WriteStartDocument()
Case XmlNodeType.CDATA
myWriter.WriteCData(myReader.Value)
Case XmlNodeType.EntityReference
myWriter.WriteEntityRef(myReader.Name)
Case XmlNodeType.ProcessingInstruction
' Handle this
Case Else
'Do nothing
End Select
End If

myWriter.Flush()
End While

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3638
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
3267
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
4
2914
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
3
1961
by: Tony Johansson | last post by:
Hello!! Assume we have one base class called Vehicle and two derived classes called Car and Bus. I would be able to call method getName on an object of class Car or Bus and return back the name...
1
2021
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
2
1712
by: gary.goodwin | last post by:
HI I am trying to understand Attribute usage. For example the class SerializableAttribute is a class correct? So why when it is actually u sed the "Attribute" portion of the name is dropped. The...
0
1965
by: Thomas Wittek | last post by:
Hi! I'm using xsl:attribute-sets to reduce redundancy in my XSLT. An example from a transformation to XHTML (the attribute values are simply copied from input to output): <xsl:attribute-set...
6
3537
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
18
6732
by: Gabriel Rossetti | last post by:
Hello everyone, I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static) attributes. I had done this and it seamed to work,...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.