Partager via


TREENODESRC Attribute | treeNodeSrc Property

Sets or retrieves a value that indicates the URL of an XML file, String, or XML data island containing TreeNode elements.

Syntax

HTML <namespace:TREEVIEW TREENODESRC = sTreeNodeSrc... >
Scripting TREEVIEW.treeNodeSrc [ = sTreeNodeSrc ]

Possible Values

namespace Prefix that associates a custom tag with an XML namespace. This prefix is set using the XMLNS attribute of the html tag.
sTreeNodeSrc String that specifies or receives the URL of an XML file, String, or XML data island containing TreeNode elements.

The property is read/write. The property has no default value.

Remarks

You can encapsulate and reuse trees or pieces of trees in an XML data island. The XML file must contain only TreeNode elements wrapped in opening and closing TREENODES tags.

When TREENODESRC is an attribute of the TreeView element, the content of the XML data island renders in place of any TreeView content. However, the TreeNodeType elements within the TreeView are not replaced.

The XML data island inherits the namespace of the databound element. The XML file must not contain any namespaces.

The XML data island must be syntactically well-formed XML.

You can transform the XML file specified by this attribute by setting the TREENODEXSLTSRC attribute to the URL of an Extensible Stylesheet Language Transformations (XSLT) file.

The XML data island must be syntactically well-formed XML.

After setting the value of this attribute, call the databind method to render the changes.

Examples

The following example demonstrates how to set the TREENODESRC attribute of the TreeView element to an XML file called treenodes.xml.

<HTML XMLNS:mytree>
<?IMPORT NAMESPACE="mytree" IMPLEMENTATION="treeview.htc"/>

<BODY>
<H1>TreeNodeSrc Sample</H1>

<mytree:TREEVIEW ID="oTree"
    DEFAULTSTYLE="font: 12pt verdana"
    SYSTEMIMAGESPATH="treeimages"
    CHILDTYPE="folder"
    TREENODESRC="treenodes.xml"
/>

</BODY>
</HTML>

Code example: https://samples.msdn.microsoft.com/workshop/samples/webcontrols/treeview/TreeNodeSrc_XmlFile.htm

The following is the content of the XML file, treenodes.xml, used in the preceding example.

<TREENODES>
    <TREENODE TEXT="Document-1" IMAGEURL="folder.gif"
        EXPANDEDIMAGEURL="folderopen.gif"/>
    <TREENODE TEXT="Folder-1" EXPANDED="true"
        IMAGEURL="folder.gif" EXPANDEDIMAGEURL="folderopen.gif">
        <TREENODE TEXT="Document-2"/>
        <TREENODE TEXT="Document-3"/>
    </TREENODE>
    <TREENODE TEXT="Document-4" IMAGEURL="folder.gif"/>
</TREENODES>

The TREENODESRC attribute of the TreeView element can also be set to a String containing the TreeNode elements as shown in the following example.

<HTML XMLNS:mytree>
<?IMPORT NAMESPACE="mytree" IMPLEMENTATION="treeview.htc"/>

<BODY>

<mytree:TREEVIEW ID="tvw1"
    DEFAULTSTYLE="font: 12pt verdana"
    SYSTEMIMAGESPATH="treeimages"
    CHILDTYPE="folder"
    TREENODESRC="<TREENODES>
        <TREENODE TEXT='Document-1'
            IMAGEURL='images/folder.gif'
            EXPANDEDIMAGEURL='images/folderopen.gif'/>
            <TREENODE TEXT='Folder-1' EXPANDED='true'
               IMAGEURL='images/folder.gif'
                EXPANDEDIMAGEURL='images/folderopen.gif'>
                <TREENODE TEXT='Document-2' />
                <TREENODE TEXT='Document-3' />
            </TREENODE>
            <TREENODE TEXT='Document-4'
                IMAGEURL='images/folder.gif'/>
        </TREENODES>"
/>

</BODY>
</HTML>

Code example: https://samples.msdn.microsoft.com/workshop/samples/webcontrols/treeview/TreeNodeSrc_String.htm

This example demonstrates how to dynamically set the TREENODESRC attribute of a TreeNode element using script to an XML data island within the primary document.

<HTML XMLNS:mytree>
<?IMPORT NAMESPACE="mytree" IMPLEMENTATION="treeview.htc"/>

<script>
function setSrc(){
    /* Sets the treeNodeSrc of the treeview to an XML data island within the primary
        document containing the treeview and treeenodes. */
    oTree.treeNodeSrc =  oXML.XMLDocument.documentElement.xml;
    oTree.databind();
}
</script>

<BODY>

<mytree:TREEVIEW id="oTree"
    DEFAULTSTYLE="font: 12pt verdana"
    SYSTEMIMAGESPATH="treeimages"
    CHILDTYPE="folder">
    <mytree:TREENODETYPE TYPE="folder" CHILDTYPE="list"
        IMAGEURL="images/folder.gif"
        EXPANDEDIMAGEURL="images/folderopen.gif"/>
    <!-- The first treeNode. -->
    <mytree:TREENODE TEXT="Some list" EXPANDED=true CHILDTYPE="folder" />
</mytree:TREEVIEW>

<BR><BR>
<BUTTON onclick="setSrc();">Click here</BUTTON>

<!-- Begin XML Data Island. -->
<XML id="oXML">
    <TREENODES>
        <TREENODE TEXT="Document-1"
            IMAGEURL="images/folder.gif"
            EXPANDEDIMAGEURL="images/folderopen.gif"/> 
        <TREENODE TEXT="Folder-1"
            IMAGEURL="images/folder.gif"
            EXPANDEDIMAGEURL="images/folderopen.gif">
            <TREENODE TEXT="Document-2" />
            <TREENODE TEXT="Document-3" />
        </TREENODE>
        <TREENODE TEXT="Document-4"
            IMAGEURL="images/folder.gif"/>
    </TREENODES>
</XML>
<!-- End XML Data Island. -->

</BODY>
</HTML>

Code example: https://samples.msdn.microsoft.com/workshop/samples/webcontrols/treeview/TreeNodeSrcProperty_XMLDataIsland.htm

Applies To

TREEVIEW

See Also

Internet Explorer WebControls, About the TreeView WebControl