Microsoft Knowledge Base Email Alertz

KBAlertz.com: 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 demons

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 299388 - Last Review: July 10, 2006 - Revision: 2.2

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

This article was previously published under Q299388

On This Page

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 <INPUT TYPE=HIDDEN> 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  (http://kbalertz.com/Feedback.aspx?kbNumber=305019/ ) MSXML 4.0 specific GUIDs and ProgIDs
For example, in the code below, you would create the objects using:
Set clientSideXMLDoc = CreateObject("MSXML2.DomDocument.4.0")
and
Set serverSideXMLDoc = Server.CreateObject("MSXML2.DomDocument.4.0")
  1. In Notepad, create a new XML document named Books.xml, and paste the following, well-formed XML:
    <?xml version="1.0"?>
     <Books> 
        <Book QTY="10">
            <Title>Beginning XML</Title>       
        </Book>
        <Book QTY="2">
           <Title>Mastering XML</Title>       
       </Book>
    </Books>
    					
  2. Save Books.xml in one of your Microsoft Internet Information Server (IIS) virtual directories.
  3. 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("Microsoft.XMLDOM")
           clientSideXMLDoc.loadxml form1.txtXML.value
           Msgbox clientSideXMLDoc.xml 
        End Sub 
       </SCRIPT>
    </HEAD>
    
    <BODY>
    <%
         Dim serverSideXMLDoc
         Set serverSideXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
         serverSideXMLDoc.load Server.MapPath("books.xml")   
    %>
    
    
    <FORM id="form1" method="POST" action="hiddenxml.asp"> 
     <INPUT ID='txtXML' name='txtXML' TYPE='hidden' VALUE='<% =serverSideXMLDoc.xml %>'> 
     <INPUT TYPE=Button id="btnXML" value="Display Hidden XML">  
    </FORM>
    
    </BODY>
    </HTML>
    					
  4. Save LoadHiddenXML.asp in the same IIS virtual directory where you saved Books.xml.
  5. 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.

APPLIES TO
  • Microsoft XML Parser 2.0
  • Microsoft XML Parser 2.5
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 3.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
Keywords: 
kbhowto KB299388
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please