Class

NSXMLElement

The element nodes in an XML tree structure. XMLツリー構造の中の要素ノード。

Declaration 宣言

@interface NSXMLElement : NSXMLNode

Overview 概要

An NSXMLElement object may have child nodes, specifically comment nodes, processing-instruction nodes, text nodes, and other NSXMLElement nodes. It may also have attribute nodes and namespace nodes associated with it (however, namespace and attribute nodes are not considered children). Any attempt to add a NSXMLDocument node, NSXMLDTD node, namespace node, or attribute node as a child raises an exception. If you add a child node to an NSXMLElement object and that child already has a parent, NSXMLElement raises an exception; the child must be detached or copied first. NSXMLElementオブジェクトは、子ノードを持つかもしれません、具体的にはコメントノード、処理命令ノード、テキストノード、そして他のNSXMLElementノード。それはまた、それと結びつけられる属性ノードと名前空間ノードを持つかもしれません(しかしながら、名前空間と属性ノードは子と見なされません)。NSXMLDocumentノード、 NSXMLDTDノード、名前空間ノード、または属性ノードを子として加えるどんな試みも、例外を引き起こします。あなたがある子ノードをNSXMLElementオブジェクトに加えるそしてその子が既に親を持つならば、NSXMLElementは例外を引き起こします;子は最初に分離またはコピーされなければなりません。

Subclassing Notes サブクラス作成の注意

You can subclass NSXMLElement if you want element nodes with more specialized attributes or behavior, for example, paragraph and font attributes that specify how the string value of the element should appear. あなたは、NSXMLElementのサブクラスを作ることができます、もしあなたがより特殊化された属性または挙動を持つ要素ノードを望むならば、例えば、段落およびフォント属性、それはどのようにその要素の文字列値が現れるべきか指定します。

Methods to Override メソッドのオーバーライド

To subclass NSXMLElement you need to override the primary initializer, initWithName:URI:, and the methods listed below. In most cases, you need only invoke the superclass implementation, adding any subclass-specific code before or after the invocation, as necessary. NSXMLElementのサブクラスを作るには、あなたはプライマリイニシャライザ initWithName:URI:、そして下で一覧にされるメソッドをオーバーライドする必要があります。ほとんどの場合には、あなたはスーパークラス実装の発動だけが必要です、何らかのサブクラス特有コードをその発動の前または後に加えます、必要に応じて。

NSXMLElement implements isEqual: to perform a deep comparison: two NSXMLDocument objects are not considered equal unless they have the same name, same child nodes, same attributes, and so on. If you want a different standard of comparison, override isEqual:. あなたが比較の異なる標準を望むならば、isEqual:をオーバーライドしてください。

Special Considerations 特別な注意事項

Because of the architecture and data model of NSXML, when it parses and processes a source of XML it cannot know about your subclass unless you override the class method replacementClassForClass: to return your custom class in place of an NSXML class. If your custom class has no direct NSXML counterpart—for example, it is a subclass of NSXMLNode that represents CDATA sections—then you can walk the tree after it has been created and insert the new node where appropriate. NSXMLのアーキテクチャとデータモデルが原因で、それがXMLのソースを構文解析して処理する時にそれはあなたのサブクラスについて知ることはできません、もしあなたがクラスメソッドreplacementClassForClass:をオーバーライドしてあなたのあつらえのクラスをNSXMLクラスの代わりに返すのでなければ。あなたのあつらえのクラスが直接のNSXML相当物を持たないならば — 例えば、それが、NSXMLNodeのサブクラスであり、CDATAセクションを表している — そのときあなたはツリーをそれが作成された後に歩いて行って(walk)、新しいノードを適切なところに挿入できます。

Note that you can safely set the root element of the XML document (using the NSXMLDocument setRootElement:method) to be an instance of your subclass because this method only checks to see if the added node is of an element kind (NSXMLElementKind). These precautions do not apply, of course, if you are creating an XML tree programmatically. 注意してください、あなたは何の問題もなくXML書類のルート要素が(NSXMLDocumentsetRootElement:メソッドを使って)あなたのサブクラスのインスタンスであると設定できます、なぜならこのメソッドは加えられたノードが要素種類(NSXMLElementKind)のものであるか見るために調べるだけだからです。これら予防措置は当てはまりません、もちろん、あなたがXMLツリーをプログラム的に作成しているならば。

Topics 話題

Initializing NSXMLElement Objects NSXMLElementオブジェクトを初期化する

Obtaining Child Elements 子要素を入手する

Manipulating Child Elements 子要素を操作する

Handling Attributes 属性を取り扱う

Handling Namespaces 名前空間を取り扱う

Initializers イニシャライザ

Relationships 関係

Inherits From 継承元

See Also 参照

Tree-Based Processing ツリー基盤の処理