XStreamingElement Class

XStreamingElement Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Represents elements in an XML tree that supports deferred streaming output.

System::Object
  System.Xml.Linq::XStreamingElement

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

No code example is currently available or this language may not be supported.

The XStreamingElement type exposes the following members.

  NameDescription
Public methodXStreamingElement(XName)Initializes a new instance of the XElement class from the specified XName.
Public methodXStreamingElement(XName, Object)Initializes a new instance of the XStreamingElement class with the specified name and content.
Public methodXStreamingElement(XName, array<Object>)Initializes a new instance of the XStreamingElement class with the specified name and content.
Top

  NameDescription
Public propertyNameGets or sets the name of this streaming element.
Top

  NameDescription
Public methodAdd(Object)Adds the specified content as children to this XStreamingElement.
Public methodAdd(array<Object>)Adds the specified content as children to this XStreamingElement.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSave(Stream)Outputs this XStreamingElement to the specified Stream.
Public methodSave(TextWriter)Serialize this streaming element to a TextWriter.
Public methodSave(XmlWriter)Serialize this streaming element to an XmlWriter.
Public methodSave(Stream, SaveOptions)Outputs this XStreamingElement to the specified Stream, optionally specifying formatting behavior.
Public methodSave(TextWriter, SaveOptions)Serialize this streaming element to a TextWriter, optionally disabling formatting.
Public methodToString()Returns the formatted (indented) XML for this streaming element. (Overrides Object::ToString().)
Public methodToString(SaveOptions)Returns the XML for this streaming element, optionally disabling formatting.
Public methodWriteToWrites this streaming element to an XmlWriter.
Top

This class allows you to create an XML tree that supports deferred streaming output. You use this class to create an XML tree in a very similar fashion to creating an XML tree using XElement. However, there is a fundamental difference. When you use a LINQ query to specify content when creating an XML tree using XElement, the query variable is iterated at the time of construction of the XML tree, and the results of the query are added to the XML tree. In contrast, when you create an XML tree using XStreamingElement, a reference to the query variable is stored in the XML tree without being iterated. Queries are iterated only upon serialization. This allows you to create larger XML trees while maintaining a smaller memory footprint.

If you are streaming from an input source, such as a text file, then you can read a very large text file, and generate a very large XML document while maintaining a small memory footprint.

Another scenario is that you have a large XML tree that has been loaded into memory, and you want to create a transformed version of the document. If you create a new document using XElement, then you will have two large XML trees in memory upon completion of the transformation. However, if you create the new XML tree using XStreamingElement, then your working set will be effectively cut in half.

Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. This causes the XML to be serialized. If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.

The following example first creates a source XML tree. It then creates a transform of the source XML tree using XElement. This transform creates a new tree in memory. It then creates a transform of the source XML tree using XStreamingElement. This transform doesn't execute the query until the transformed tree is serialized to the console. Its memory usage is less.

No code example is currently available or this language may not be supported.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft