XmlTextReader.WhitespaceHandling プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlTextReader.WhitespaceHandling プロパティの意味・解説 

XmlTextReader.WhitespaceHandling プロパティ

空白処理方法指定する値を取得または設定します

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Property WhitespaceHandling As
 WhitespaceHandling
Dim instance As XmlTextReader
Dim value As WhitespaceHandling

value = instance.WhitespaceHandling

instance.WhitespaceHandling = value
public WhitespaceHandling WhitespaceHandling { get;
 set; }
public:
property WhitespaceHandling WhitespaceHandling {
    WhitespaceHandling get ();
    void set (WhitespaceHandling value);
}
/** @property */
public WhitespaceHandling get_WhitespaceHandling ()

/** @property */
public void set_WhitespaceHandling (WhitespaceHandling
 value)
public function get WhitespaceHandling
 () : WhitespaceHandling

public function set WhitespaceHandling
 (value : WhitespaceHandling)

プロパティ
WhitespaceHandling 値の 1 つ既定値WhitespaceHandling.All で、Whitespace ノードSignificantWhitespace ノード返します

例外例外
例外種類条件

ArgumentOutOfRangeException

無効な値を指定してます。

InvalidOperationException

リーダー閉じているとき (ReadState が ReadState.Closed のとき) にこのプロパティ設定します

解説解説
使用例使用例

XML フラグメント読み取る例を次に示します

Imports System
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    'Create the XML fragment to be parsed.
    Dim xmlFrag as string
 ="<book> " & _
                           "  <title>Pride And Prejudice</title>"
 & _
                           "  <genre>novel</genre>"
 & _
                           "</book>" 

    'Create the XmlNamespaceManager.
    Dim nt as NameTable = new
 NameTable()
    Dim nsmgr as XmlNamespaceManager = new
 XmlNamespaceManager(nt)

    'Create the XmlParserContext.
    Dim context as XmlParserContext = new
 XmlParserContext(nothing, nsmgr, nothing,
 XmlSpace.Default)

    Console.WriteLine("Read the XML and ignore all white space...")
    ReadXML(context, xmlFrag, WhitespaceHandling.None)

    Console.WriteLine()
    Console.WriteLine("Read the XML including white space nodes...")
    ReadXML(context, xmlFrag, WhitespaceHandling.All)
  end sub
  
  public shared sub ReadXML(context
 as XmlParserContext, xmlFrag as string,
 ws as WhitespaceHandling)

    'Create the reader and specify the WhitespaceHandling setting.
    Dim reader as XmlTextReader = new
 XmlTextReader(xmlFrag, XmlNodeType.Element, context)
    reader.WhitespaceHandling = ws

      'Parse the XML and display each of the nodes.
      while (reader.Read())
         select case reader.NodeType
           case XmlNodeType.Element:
             Console.WriteLine("{0}: <{1}>",
 reader.NodeType, reader.Name)
           case XmlNodeType.Text:
             Console.WriteLine("{0}: {1}", reader.NodeType,
 reader.Value)
           case XmlNodeType.EndElement:
             Console.WriteLine("{0}: </{1}>",
 reader.NodeType, reader.Name)
           case XmlNodeType.Whitespace:
             Console.WriteLine("{0}:", reader.NodeType)
           case XmlNodeType.SignificantWhitespace:
             Console.WriteLine("{0}:", reader.NodeType)
         end select       
      end while           
  
    'Close the reader.
    reader.Close()     
  
  end sub
end class

using System;
using System.IO;
using System.Xml;

public class Sample 
{
  public static void Main(){

    //Create the XML fragment to be parsed.
    string xmlFrag ="<book> " +
                    "  <title>Pride And Prejudice</title>"
 +
                    "  <genre>novel</genre>" +
                    "</book>"; 

    //Create the XmlNamespaceManager.
    NameTable nt = new NameTable();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

    //Create the XmlParserContext.
    XmlParserContext context = new XmlParserContext(null,
 nsmgr, null, XmlSpace.Default);

    Console.WriteLine("Read the XML and ignore all white space...");
    ReadXML(context, xmlFrag, WhitespaceHandling.None);

    Console.WriteLine("\r\nRead the XML including white space nodes...");
    ReadXML(context, xmlFrag, WhitespaceHandling.All);

  }
  
  public static void ReadXML(XmlParserContext
 context, string xmlFrag, WhitespaceHandling ws){

    //Create the reader and specify the WhitespaceHandling setting.
    XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
 context);
    reader.WhitespaceHandling = ws;

      //Parse the XML and display each of the nodes.
      while (reader.Read())
      {
         switch (reader.NodeType)
         {
           case XmlNodeType.Element:
             Console.WriteLine("{0}: <{1}>", reader.NodeType, reader.Name);
             break;
           case XmlNodeType.Text:
             Console.WriteLine("{0}: {1}", reader.NodeType, reader.Value);
             break;
           case XmlNodeType.EndElement:
             Console.WriteLine("{0}: </{1}>", reader.NodeType, reader.Name);
             break;
           case XmlNodeType.Whitespace:
             Console.WriteLine("{0}:", reader.NodeType);
             break;
           case XmlNodeType.SignificantWhitespace:
             Console.WriteLine("{0}:", reader.NodeType);
             break;
         }       
      }           
  
    //Close the reader.
    reader.Close();     
  
  }
} // End class

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
void ReadXML( XmlParserContext^ context, String^ xmlFrag, WhitespaceHandling
 ws )
{
   
   //Create the reader and specify the WhitespaceHandling setting.
   XmlTextReader^ reader = gcnew XmlTextReader( xmlFrag,XmlNodeType::Element,context
 );
   reader->WhitespaceHandling = ws;
   
   //Parse the XML and display each of the nodes.
   while ( reader->Read() )
   {
      switch ( reader->NodeType )
      {
         case XmlNodeType::Element:
            Console::WriteLine( "{0}: <{1}>", reader->NodeType,
 reader->Name );
            break;

         case XmlNodeType::Text:
            Console::WriteLine( "{0}: {1}", reader->NodeType, reader->Value
 );
            break;

         case XmlNodeType::EndElement:
            Console::WriteLine( "{0}: </{1}>", reader->NodeType,
 reader->Name );
            break;

         case XmlNodeType::Whitespace:
            Console::WriteLine( "{0}:", reader->NodeType );
            break;

         case XmlNodeType::SignificantWhitespace:
            Console::WriteLine( "{0}:", reader->NodeType );
            break;
      }
   }

   
   //Close the reader.
   reader->Close();
}

int main()
{
   
   //Create the XML fragment to be parsed.
   String^ xmlFrag = "<book> "
   "  <title>Pride And Prejudice</title>"
   "  <genre>novel</genre>"
   "</book>";
   
   //Create the XmlNamespaceManager.
   NameTable^ nt = gcnew NameTable;
   XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager( nt );
   
   //Create the XmlParserContext.
   XmlParserContext^ context = gcnew XmlParserContext( nullptr,nsmgr,nullptr,XmlSpace::Default
 );
   Console::WriteLine( "Read the XML and ignore all white space..." );
   ReadXML( context, xmlFrag, WhitespaceHandling::None );
   Console::WriteLine( "\r\nRead the XML including white space nodes..."
 );
   ReadXML( context, xmlFrag, WhitespaceHandling::All );
}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[]
 args)
    {
        //Create the XML fragment to be parsed.
        String xmlFrag = "<book> " + "  <title>Pride And
 Prejudice</title>" 
            + "  <genre>novel</genre>" + "</book>";

        //Create the XmlNamespaceManager.
        NameTable nt =  new NameTable();
        XmlNamespaceManager nsMgr =  new XmlNamespaceManager(nt);

        //Create the XmlParserContext.
        XmlParserContext context =  new XmlParserContext
            (null, nsMgr, null, XmlSpace.Default);
        Console.WriteLine("Read the XML and ignore all white space...");
        ReadXML(context, xmlFrag, WhitespaceHandling.None);
        Console.WriteLine("\r\nRead the XML including white space nodes...");
        ReadXML(context, xmlFrag, WhitespaceHandling.All);
    } //main

    public static void ReadXML(XmlParserContext
 context, String xmlFrag,
        WhitespaceHandling ws)
    {
        //Create the reader and specify the WhitespaceHandling setting.
        XmlTextReader reader = 
            new XmlTextReader(xmlFrag, XmlNodeType.Element, context);
        reader.set_WhitespaceHandling(ws);

        //Parse the XML and display each of the nodes.
        while(reader.Read()) {
            switch(reader.get_NodeType()) {
                case XmlNodeType.Element : 
                    Console.WriteLine("{0}: <{1}>", 
                        reader.get_NodeType(), reader.get_Name());
                    break;
                case XmlNodeType.Text : 
                    Console.WriteLine("{0}: {1}", 
                        reader.get_NodeType(), reader.get_Value());
                    break;
                case XmlNodeType.EndElement : 
                    Console.WriteLine("{0}: </{1}>", 
                        reader.get_NodeType(), reader.get_Name());
                    break;
                case XmlNodeType.Whitespace : 
                    Console.WriteLine("{0}:", reader.get_NodeType());
                    break;
                case XmlNodeType.SignificantWhitespace : 
                    Console.WriteLine("{0}:", reader.get_NodeType());
                    break;
            }
        }
        //Close the reader.
        reader.Close();
    } //ReadXML 
} // End class Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlTextReader.WhitespaceHandling プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlTextReader.WhitespaceHandling プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlTextReader.WhitespaceHandling プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlTextReader.WhitespaceHandling プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlTextReader.WhitespaceHandling プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS