YouTip LogoYouTip

Prop Webcontrol Xml Documentsource

## ASP.NET XML Control: DocumentSource Property The `DocumentSource` property is a key property of the ASP.NET `Xml` web control. It is used to specify or retrieve the path to the XML document that you want to display or manipulate within the control. --- ## Definition and Usage The `DocumentSource` property binds an external XML file to the `` control. When the page renders, the control loads the XML content from the specified path and outputs it directly to the page (or transforms it first if a stylesheet is applied via the `TransformSource` property). --- ## Syntax ```xml ``` ### Property Values | Property Value | Description | | :--- | :--- | | `path` | A string value specifying the location of the XML file.

**Supported Path Types:**
β€’ **Relative Path:** Relative to the location of the current page (e.g., `"~/App_Data/note.xml"` or `"note.xml"`).
β€’ **Absolute Path:** A physical path on the server (e.g., `"C:\xml\note.xml"`). | --- ## Code Example The following example demonstrates how to load and display an external XML file named `note.xml` using the `DocumentSource` property. ### The XML File (`note.xml`) ```xml Tove Jani Reminder Don't forget me this weekend! ``` ### The ASPX Page ```html <%@ Page Language="C#" %> ASP.NET Xml DocumentSource Example
``` --- ## Important Considerations 1. **Path Resolution:** Using the tilde operator (`~/`) is highly recommended for web applications. It represents the root directory of the application, ensuring that paths resolve correctly even if the page is moved to a different subfolder (e.g., `DocumentSource="~/App_Data/note.xml"`). 2. **Alternative Properties:** * If your XML data is stored in a string variable or generated dynamically in code-behind, use the **`Document`** property (which accepts an `XmlDocument` object) or the **`DocumentContent`** property (which accepts a raw XML string) instead of `DocumentSource`. 3. **Styling the Output:** By default, raw XML loaded via `DocumentSource` might not render in a user-friendly format in the browser. To format and style the XML output into HTML, pair the `DocumentSource` property with the **`TransformSource`** property to apply an XSLT stylesheet.
← Python Files IoProp Webcontrol Textbox Wrap β†’