Mac Developer Library

Developer

Foundation Framework Reference NSXMLElement Class Reference

Options
Deployment Target:

On This Page
Language:

NSXMLElement

Instances of the NSXMLElement class represent element nodes in an XML tree structure. 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. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.4 and later.
  • Returns an NSXMLElement object initialized with the specified name.

    Declaration

    Swift

    convenience init(name name: String)

    Objective-C

    - (instancetype)initWithName:(NSString *)name

    Parameters

    name

    A string specifying the name of the element.

    Return Value

    The initialized NSXMLElement object or nil if initialization did not succeed.

    Discussion

    The XML string representation of this object is <name></name>. This method invokes initWithName:URI: with the URI parameter set to nil.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • Returns an NSXMLElement object initialized with a specified name and a single text-node child containing a specified value.

    Declaration

    Swift

    convenience init(name name: String, stringValue string: String?)

    Objective-C

    - (instancetype)initWithName:(NSString *)name stringValue:(NSString *)string

    Parameters

    name

    A string specifying the name of the element.

    string

    The string value of the receiver's text node.

    Return Value

    The initialized NSXMLElement object or nil if initialization did not succeed.

    Discussion

    The string representation of this object is <name>string</name>.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • Returns an NSXMLElement object created from a specified string containing XML markup.

    Declaration

    Swift

    init?(XMLString string: String, error error: NSErrorPointer)

    Objective-C

    - (instancetype)initWithXMLString:(NSString *)string error:(NSError **)error

    Parameters

    string

    A string containing XML markup for an element.

    error

    On return, an NSError object that describes any errors or warnings resulting from the parsing of the markup.

    Return Value

    The initialized NSXMLElement object or nil if initialization did not succeed.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • init(name:URI:) initWithName:URI: Designated Initializer

    Returns an NSXMLElement object initialized with the specified name and URI.

    Declaration

    Swift

    init(name name: String, URI URI: String?)

    Objective-C

    - (instancetype)initWithName:(NSString *)name URI:(NSString *)URI

    Parameters

    name

    A string that specifies the qualified name of the element.

    URI

    A string that specifies the namespace URI associated with the element.

    Return Value

    The initialized NSXMLElement object or nil if initialization did not succeed.

    Discussion

    You can look up the namespace prefix for this element node based on its URI using resolvePrefixForNamespaceURI:. This method is the primary initializer for the NSXMLElement class.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • Returns the child element nodes (as NSXMLElement objects) of the receiver that have a specified name.

    Declaration

    Swift

    func elementsForName(_ name: String) -> [AnyObject]

    Objective-C

    - (NSArray *)elementsForName:(NSString *)name

    Parameters

    name

    A string specifying the name of the child element nodes to find and return. If name is a qualified name, then this method invokes elementsForLocalName:URI: with the URI parameter set to the URI associated with the prefix. Otherwise comparison is based on string equality of the qualified or non-qualified name.

    Return Value

    An array of of NSXMLElement objects or an empty array if no matching children can be found.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • Returns the child element nodes (as NSXMLElement objects) of the receiver that are matched with the specified local name and URI.

    Declaration

    Swift

    func elementsForLocalName(_ localName: String, URI URI: String?) -> [AnyObject]

    Objective-C

    - (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)URI

    Parameters

    localName

    A string specifying a local name of an element.

    URI

    A string specifying a URI associated with an element.

    Return Value

    An array of NSXMLElement objects or an empty array if no matching children could be found.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.4 and later.