//----------------------------------------------------------------------- // This file is part of the Microsoft .NET SDK Code Samples. // // Copyright (C) Microsoft Corporation. All rights reserved. // //This source code is intended only as a supplement to Microsoft //Development Tools and/or on-line documentation. See these other //materials for detailed information regarding Microsoft code samples. // //THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY //KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE //IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //PARTICULAR PURPOSE. //----------------------------------------------------------------------- #using using namespace System; using namespace System::IO; using namespace System::Xml; namespace MicrosoftSamplesXml { public ref class ReadXmlStreamSample { public: void Main() { StringReader^ stream = nullptr; XmlReader^ reader = nullptr; XmlWriter^ writer = nullptr; Uri^ uri = nullptr; try { Console::WriteLine( "Initializing StringReader ..." ); stream = gcnew StringReader( String::Concat( L"", L"", L"", L" ", L" The Autobiography of Benjamin Franklin", L" ", L" Benjamin", L" Franklin", L" ", L" 8.99", L" ", L" ", L" The Confidence Man", L" ", L" Herman", L" Melville", L" ", L" 11.99", L" ", L" ", L" The Gorgias", L" ", L" Plato", L" ", L" 9.99", L" ", L"" ) ); // Create XmlReader and load reader from the stream uri = gcnew Uri( L"http://tempuri.org/unknown" ); reader = XmlReader::Create( stream ); //Output reader to console writer = XmlWriter::Create( Console::Out ); writer->WriteNode( reader, true ); writer->Flush(); } finally { Console::WriteLine("Processing of stream complete."); Console::WriteLine("Press Enter to Exit"); Console::ReadLine(); // Finished with XmlReader if ( reader != nullptr ) { reader->Close(); } if (writer != nullptr) { writer->Close(); } if (stream != nullptr) { stream->Close(); } } } }; } void main() { //Import the new package using namespace MicrosoftSamplesXml; //Create the ReadXmlStreamSample class ReadXmlStreamSample^ readXmlStreamSample = gcnew ReadXmlStreamSample; readXmlStreamSample->Main(); }