XmlTextWriter::XmlSpace Property
.NET Framework (current version)
Gets an XmlSpace representing the current xml:space scope.
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.Xml::XmlSpaceAn XmlSpace representing the current xml:space scope.
Value | Meaning |
|---|---|
None | This is the default if no xml:space scope exists. |
Default | The current scope is xml:space="default". |
Preserve | The current scope is xml:space="preserve". |
Note |
|---|
Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter::Create method and the XmlWriterSettings class to take advantage of new functionality. |
This property allows one component to find out in what state another component has left the writer.
The following example uses the WriteWhitespace method to control how the file is formatted.
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { // Create the writer. XmlTextWriter^ writer = nullptr; writer = gcnew XmlTextWriter( "ws.html", nullptr ); // Write an element (this one is the root). writer->WriteStartElement( "p" ); // Write the xml:space attribute. writer->WriteAttributeString( "xml", "space", nullptr, "preserve" ); // Verify that xml:space is set properly. if ( writer->XmlSpace == XmlSpace::Preserve ) Console::WriteLine( "xmlspace is correct!" ); // Write out the HTML elements. Insert white space // between 'something' and 'Big' writer->WriteString( "something" ); writer->WriteWhitespace( " " ); writer->WriteElementString( "b", "B" ); writer->WriteString( "ig" ); // Write the root end element. writer->WriteEndElement(); // Write the XML to file and close the writer. writer->Close(); }
.NET Framework
Available since 1.1
Available since 1.1
Show:
