XmlDocumentType.Entities 属性


获取文档类型声明中声明的 XmlEntity 节点的集合。Gets the collection of XmlEntity nodes declared in the document type declaration.

 property System::Xml::XmlNamedNodeMap ^ Entities { System::Xml::XmlNamedNodeMap ^ get(); };
public System.Xml.XmlNamedNodeMap Entities { get; }
member this.Entities : System.Xml.XmlNamedNodeMap
Public ReadOnly Property Entities As XmlNamedNodeMap



包含 XmlEntity 节点的 XmlNamedNodeMapAn XmlNamedNodeMap containing the XmlEntity nodes. 返回的 XmlNamedNodeMap 是只读的。The returned XmlNamedNodeMap is read-only.


下面的示例显示有关在 XML 文档中声明的实体的信息。The following example displays information about the entities declared in the XML document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
public ref class Sample
   static void DisplayEntities( XmlNamedNodeMap^ nMap )
      for ( int i = 0; i < nMap->Count; i++ )
         XmlEntity^ ent = dynamic_cast<XmlEntity^>(nMap->Item( i ));
         Console::Write( " {0} ", ent->NodeType );
         Console::Write( " {0} ", ent->Name );
         Console::Write( " {0} ", ent->NotationName );
         Console::Write( " {0} ", ent->PublicId );
         Console::Write( " {0} ", ent->SystemId );



int main()
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "doment.xml" );
   Console::WriteLine( "Display information on all entities..." );
   XmlNamedNodeMap^ nMap = doc->DocumentType->Entities;
   Sample^ MySample = gcnew Sample;
   MySample->DisplayEntities( nMap );

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

public class Sample
  private const String filename = "doment.xml";

  public static void Main()
     XmlDocument doc = new XmlDocument();

     Console.WriteLine("Display information on all entities...");
     XmlNamedNodeMap nMap = doc.DocumentType.Entities;

  public static void DisplayEntities(XmlNamedNodeMap nMap)
     for (int i=0; i < nMap.Count; i++)
        XmlEntity ent = (XmlEntity) nMap.Item(i);
        Console.Write("{0} ", ent.NodeType);
        Console.Write("{0} ", ent.Name);
        Console.Write("{0} ", ent.NotationName);
        Console.Write("{0} ", ent.PublicId);
        Console.Write("{0} ", ent.SystemId);
Imports System.IO
Imports System.Xml

public class Sample

  private const filename as String = "doment.xml"
  public shared sub Main()
     Dim doc as XmlDocument = new XmlDocument()
     Console.WriteLine("Display information on all entities...")     
     Dim nMap as XmlNamedNodeMap = doc.DocumentType.Entities
  end sub
  public shared sub DisplayEntities(nMap as XmlNamedNodeMap)
     Dim i as integer   
     for i = 0 to nMap.Count - 1
        Dim ent as XmlEntity = CType(nMap.Item(i), XmlEntity)
        Console.Write("{0} ", ent.NodeType)
        Console.Write("{0} ", ent.Name)
        Console.Write("{0} ", ent.NotationName)
        Console.Write("{0} ", ent.PublicId)
        Console.Write("{0} ", ent.SystemId)
  end sub
end class

该示例使用文件 doment.xml 作为输入。The example uses the file doment.xml as input.

<!DOCTYPE doc [

  <!ELEMENT doc ANY>
  <!NOTATION w SYSTEM "wine.exe">
  <!NOTATION v PUBLIC "vine.exe">

  <!NOTATION jpg PUBLIC "Jpeg picture format">
  <!NOTATION gif SYSTEM "Gif picture format">

  <!ENTITY wn PUBLIC "http://www.cohowinery.com" "coho.exe" NDATA w>
  <!ENTITY vn SYSTEM "http://www.cohovineyard.com" NDATA v>
  <!ENTITY mytxt "Text Sample">

  <!ATTLIST doc 
        src     ENTITY         #IMPLIED
        srcs    ENTITIES       #IMPLIED
        jpgPic  NOTATION (jpg) #IMPLIED
        gifPic  NOTATION (gif) #REQUIRED>

<doc jpgPic="jpg" gifPic="gif" srcs="vn wn">


返回实体的顺序并不取决于这些项在文档中的显示顺序。The order in which the entities are returned is not based on the order in which these items may appear in the document. 此顺序也不能保证相同的文档之间,也不能保证类的不同实现或版本之间的顺序相同。The order is also not guaranteed to be the same between similar documents, or between different implementations or versions of the class.