Title: saveDomDocument
Published: April 25, 2014
Last modified: April 28, 2025

---

# saveDomDocument( DOMDocument $doc, string $filename )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#wp--skip-link--target)

Saves the XML document into a file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#parameters)󠁿

 `$doc`DOMDocumentrequired

`$filename`stringrequired

## 󠀁[Source](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#source)󠁿

    ```php
    function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    	$config = $doc->saveXML();
    	$config = preg_replace( "/([^\r])\n/", "$1\r\n", $config );

    	$fp = fopen( $filename, 'w' );
    	fwrite( $fp, $config );
    	fclose( $fp );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/misc.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/misc.php#L981)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/misc.php#L981-L988)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#related)󠁿

| Used by | Description | 
| [iis7_delete_rewrite_rule()](https://developer.wordpress.org/reference/functions/iis7_delete_rewrite_rule/)`wp-admin/includes/misc.php` |

Deletes WordPress rewrite rule from web.config file if it exists there.

  | 
| [iis7_add_rewrite_rule()](https://developer.wordpress.org/reference/functions/iis7_add_rewrite_rule/)`wp-admin/includes/misc.php` |

Adds WordPress rewrite rule to the IIS 7+ configuration file.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/savedomdocument/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fsavedomdocument%2F)
before being able to contribute a note or feedback.