Microsoft KB Archive/299388

= How to persist server-side XML in a client-side, hidden HTML element =

Article ID: 299388

Article Last Modified on 7/10/2006

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Core Services 4.0
 * Microsoft Active Server Pages 4.0
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q299388



SUMMARY
To persist server-side XML in client-side, hidden HTML elements and access it in client-side script, you can use a combination of server-side Active Server Pages (ASP) and client-side scripts. This article includes a code sample that demonstrates how to implement this process.



MORE INFORMATION
It is a common programming requirement to persist server-side XML in client-side HTML elements so that the XML is accessible to client-side script. One method is to use the XML Data Source object (DSO) in the client-side HTML to reference and store the XML data. However, this method does not provide a cross-browser solution because the XML DSO is an Internet Explorer-specific object.

Another method is to use standard HTML in an  HTML element to persist the XML. You can then use the Value property of the hidden HTML element in client-side script to access the XML that is persisted in it. Then, the client-side script can run custom code to manipulate the XML (for example, load the XML into an instance of an XML Document Object Model object on the client, and persist the XML to disk).

Step-by-step example
If a newer version of MSXML has been installed in Side-by-Side mode, then to run the sample code with that specific version, you must explicitly use the GUIDs or ProgIDs for that version. For example, MSXML version 4 only installs in side-by-side mode. Please refer to the following article in the Microsoft Knowledge Base to see what code changes required to run the sample code with the MSXML 4.0 parser:

305019 MSXML 4.0 specific GUIDs and ProgIDs

For example, in the code below, you would create the objects using:

Set clientSideXMLDoc = CreateObject(&quot;MSXML2.DomDocument.4.0&quot;)

and

Set serverSideXMLDoc = Server.CreateObject(&quot;MSXML2.DomDocument.4.0&quot;)

  In Notepad, create a new XML document named Books.xml, and paste the following, well-formed XML:    Beginning XML   Mastering XML  </Books> </li> <li>Save Books.xml in one of your Microsoft Internet Information Server (IIS) virtual directories.</li> <li> In Notepad, create a new ASP page named LoadHiddenXML.asp, and paste the following code: <HTML>

<HEAD> <SCRIPT Language=VBScript> Sub btnXML_onClick Dim clientSideXMLDoc Set clientSideXMLDoc = CreateObject(&quot;Microsoft.XMLDOM&quot;) clientSideXMLDoc.loadxml form1.txtXML.value Msgbox clientSideXMLDoc.xml End Sub </SCRIPT> </HEAD>

<BODY> <%    Dim serverSideXMLDoc Set serverSideXMLDoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;) serverSideXMLDoc.load Server.MapPath(&quot;books.xml&quot;) %>

<FORM id=&quot;form1&quot; method=&quot;POST&quot; action=&quot;hiddenxml.asp&quot;> <INPUT ID='txtXML' name='txtXML' TYPE='hidden' VALUE='<% =serverSideXMLDoc.xml %>'> <INPUT TYPE=Button id=&quot;btnXML&quot; value=&quot;Display Hidden XML&quot;> </FORM>

</BODY> </HTML> </li> <li>Save LoadHiddenXML.asp in the same IIS virtual directory where you saved Books.xml.</li> <li>The ASP code contains server-side script to load the contents of Books.xml into an instance of the Microsoft XML (MSXML) Document Object Model (DOM). The loaded XML is then assigned as the value of the hidden HTML element named txtXML.

Open Internet Explorer, and browse to LoadHiddenXML.asp. When the page is displayed, click Display Hidden XML to load and display the XML (using a client-side MSXML DOM object) that the server-side ASP script assigns to the txtXML hidden element.</li></ol>

Additional query words: execute

Keywords: kbhowto KB299388

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.