<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.8.0"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFXMLTreeCreateFromDataWithError",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFXMLTreeCreateFromDataWithError"
  },
  "title" : "CFXMLTreeCreateFromDataWithError"
}
-->

# CFXMLTreeCreateFromDataWithError

Parses the given XML data and returns the resulting CFXMLTree object and any error information.

```
extern CFXMLTreeRefCFXMLTreeCreateFromDataWithError(CFAllocatorRef allocator, CFDataRef xmlData, CFURLRef dataSource, CFOptionFlags parseOptions, CFIndex versionOfNodes, CFDictionaryRef*errorDict);
```

## Parameters

`allocator`

The allocator to use to allocate memory for the new object. Pass `NULL` or kCFAllocatorDefault to use the current default allocator.

`xmlData`

The XML data you wish to parse.

`dataSource`

The URL from which the XML data was obtained. The URL is used to resolve any relative references found in `xmlData`. Pass `NULL` if a valid URL is unavailable.

`parseOptions`

Flags which control how the XML data will be parsed. See [`CFXMLParserOptions`](/documentation/CoreFoundation/CFXMLParserOptions) for the list of available options.

`versionOfNodes`

Determines which version of CFXMLNode objects are produced by the parser. The current version is 1.

`errorDict`

Upon return, if an error occurs contains a CFDictionary object that describes the error. If no errors occur, this parameter is not changed. Pass `NULL` if you don’t want error information. See [Error Dictionary Keys](/documentation/CoreFoundation/error-dictionary-keys) for a description of the key-value pairs in this dictionary. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Return Value

A new CFXMLTree object containing the data from the specified XML document. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

Use this function instead of [`CFXMLTreeCreateFromData`](/documentation/CoreFoundation/CFXMLTreeCreateFromData) if you need access to XML parsing errors.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)