XmlWhitespace.NodeType 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
노드의 형식을 가져옵니다.
public:
virtual property System::Xml::XmlNodeType NodeType { System::Xml::XmlNodeType get(); };
public override System.Xml.XmlNodeType NodeType { get; }
member this.NodeType : System.Xml.XmlNodeType
Public Overrides ReadOnly Property NodeType As XmlNodeType
속성 값
XmlWhitespace
노드의 경우 이 값은 Whitespace입니다.
예제
다음은 문서에 공백 노드를 추가하는 예제입니다.
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
public ref class Sample
{
private:
XmlNode^ currNode;
XmlTextReader^ reader;
public:
Sample()
{
String^ filename = "space.xml";
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<author>"
"<first-name>Eva</first-name>"
"<last-name>Corets</last-name>"
"</author>" );
Console::WriteLine( "InnerText before..." );
Console::WriteLine( doc->DocumentElement->InnerText );
// Add white space.
currNode = doc->DocumentElement;
XmlWhitespace^ ws = doc->CreateWhitespace( "\r\n" );
currNode->InsertAfter( ws, currNode->FirstChild );
Console::WriteLine();
Console::WriteLine( "InnerText after..." );
Console::WriteLine( doc->DocumentElement->InnerText );
// Save and then display the file.
doc->Save( filename );
Console::WriteLine();
Console::WriteLine( "Reading file..." );
ReadFile( filename );
}
// Parse the file and display each node.
void ReadFile( String^ filename )
{
try
{
reader = gcnew XmlTextReader( filename );
String^ sNodeType = nullptr;
while ( reader->Read() )
{
sNodeType = NodeTypeToString( reader->NodeType );
// Print the node type, name, and value.
Console::WriteLine( "{0}<{1}> {2}", sNodeType, reader->Name, reader->Value );
}
}
finally
{
if ( reader != nullptr )
reader->Close();
}
}
static String^ NodeTypeToString( XmlNodeType nodetype )
{
String^ sNodeType = nullptr;
switch ( nodetype )
{
case XmlNodeType::None:
sNodeType = "None";
break;
case XmlNodeType::Element:
sNodeType = "Element";
break;
case XmlNodeType::Attribute:
sNodeType = "Attribute";
break;
case XmlNodeType::Text:
sNodeType = "Text";
break;
case XmlNodeType::Comment:
sNodeType = "Comment";
break;
case XmlNodeType::Document:
sNodeType = "Document";
break;
case XmlNodeType::Whitespace:
sNodeType = "Whitespace";
break;
case XmlNodeType::SignificantWhitespace:
sNodeType = "SignificantWhitespace";
break;
case XmlNodeType::EndElement:
sNodeType = "EndElement";
break;
}
return sNodeType;
}
};
int main()
{
gcnew Sample;
}
using System;
using System.IO;
using System.Xml;
public class Sample {
private XmlNode currNode;
private const String filename="space.xml";
XmlTextReader reader=null;
public static void Main() {
Sample test = new Sample();
}
public Sample() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<author>" +
"<first-name>Eva</first-name>"+
"<last-name>Corets</last-name>" +
"</author>");
Console.WriteLine("InnerText before...");
Console.WriteLine(doc.DocumentElement.InnerText);
// Add white space.
currNode=doc.DocumentElement;
XmlWhitespace ws = doc.CreateWhitespace("\r\n");
currNode.InsertAfter(ws, currNode.FirstChild);
Console.WriteLine();
Console.WriteLine("InnerText after...");
Console.WriteLine(doc.DocumentElement.InnerText);
// Save and then display the file.
doc.Save(filename);
Console.WriteLine();
Console.WriteLine("Reading file...");
ReadFile(filename);
}
// Parse the file and display each node.
public void ReadFile(String filename) {
try {
reader = new XmlTextReader(filename);
String sNodeType = null;
while (reader.Read()) {
sNodeType = NodeTypeToString(reader.NodeType);
// Print the node type, name, and value.
Console.WriteLine("{0}<{1}> {2}", sNodeType, reader.Name, reader.Value);
}
}
finally
{
if (reader != null)
reader.Close();
}
}
public static String NodeTypeToString(XmlNodeType nodetype) {
String sNodeType = null;
switch (nodetype) {
case XmlNodeType.None:
sNodeType = "None";
break;
case XmlNodeType.Element:
sNodeType = "Element";
break;
case XmlNodeType.Attribute:
sNodeType = "Attribute";
break;
case XmlNodeType.Text:
sNodeType = "Text";
break;
case XmlNodeType.Comment:
sNodeType = "Comment";
break;
case XmlNodeType.Document:
sNodeType = "Document";
break;
case XmlNodeType.Whitespace:
sNodeType = "Whitespace";
break;
case XmlNodeType.SignificantWhitespace:
sNodeType = "SignificantWhitespace";
break;
case XmlNodeType.EndElement:
sNodeType = "EndElement";
break;
}
return sNodeType;
}
}
Option Strict
Option Explicit
Imports System.IO
Imports System.Xml
Public Class Sample
Private currNode As XmlNode
Private filename As String = "space.xml"
Private reader As XmlTextReader = Nothing
Public Shared Sub Main()
Dim test As New Sample()
End Sub
Public Sub New()
Dim doc As New XmlDocument()
doc.LoadXml("<author>" & _
"<first-name>Eva</first-name>"& _
"<last-name>Corets</last-name>" & _
"</author>")
Console.WriteLine("InnerText before...")
Console.WriteLine(doc.DocumentElement.InnerText)
' Add white space.
currNode = doc.DocumentElement
Dim ws As XmlWhitespace = doc.CreateWhitespace(ControlChars.Lf & ControlChars.Cr)
currNode.InsertAfter(ws, currNode.FirstChild)
Console.WriteLine()
Console.WriteLine("InnerText after...")
Console.WriteLine(doc.DocumentElement.InnerText)
' Save and then display the file.
doc.Save(filename)
Console.WriteLine()
Console.WriteLine("Reading file...")
ReadFile(filename)
End Sub
' Parse the file and display each node.
Public Sub ReadFile(filename As String)
Try
reader = New XmlTextReader(filename)
Dim sNodeType As String = Nothing
While reader.Read()
sNodeType = NodeTypeToString(reader.NodeType)
' Print the node type, name, and value.
Console.WriteLine("{0}<{1}> {2}", sNodeType, reader.Name, reader.Value)
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
Public Shared Function NodeTypeToString(nodetype As XmlNodeType) As String
Dim sNodeType As String = Nothing
Select Case nodetype
Case XmlNodeType.None
sNodeType = "None"
Case XmlNodeType.Element
sNodeType = "Element"
Case XmlNodeType.Attribute
sNodeType = "Attribute"
Case XmlNodeType.Text
sNodeType = "Text"
Case XmlNodeType.Comment
sNodeType = "Comment"
Case XmlNodeType.Document
sNodeType = "Document"
Case XmlNodeType.Whitespace
sNodeType = "Whitespace"
Case XmlNodeType.SignificantWhitespace
sNodeType = "SignificantWhitespace"
Case XmlNodeType.EndElement
sNodeType = "EndElement"
End Select
Return sNodeType
End Function 'NodeTypeToString
End Class