﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-beautykingdom-随笔分类-browser</title><link>http://www.cppblog.com/beautykingdom/category/10081.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 09 Dec 2009 13:22:52 GMT</lastBuildDate><pubDate>Wed, 09 Dec 2009 13:22:52 GMT</pubDate><ttl>60</ttl><item><title>Document Object Model&lt;from wiki pedia&gt;</title><link>http://www.cppblog.com/beautykingdom/archive/2009/04/24/80945.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 24 Apr 2009 07:06:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2009/04/24/80945.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/80945.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2009/04/24/80945.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/80945.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/80945.html</trackback:ping><description><![CDATA[http://en.wikipedia.org/wiki/Document_Object_Model<br><br>
<h1 id="firstHeading" class="firstHeading">Document Object Model</h1>
<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3>
<div id="jump-to-nav">Jump to: <a  href="http://en.wikipedia.org/wiki/Document_Object_Model#column-one">navigation</a>, <a  href="http://en.wikipedia.org/wiki/Document_Object_Model#searchInput">search</a></div>
<!-- start content -->
<div class="dablink">For Domain Object Model, see <a  href="http://en.wikipedia.org/wiki/Domain_Model" title="Domain model" class="mw-redirect">Domain Model</a>.</div>
<div class="thumb tright">
<div class="thumbinner" style="width: 302px;"><a  href="http://en.wikipedia.org/wiki/File:JKDOM.SVG" class="image" title="Hierarchy of objects in an example HTML DOM - Document Object Model"><img  src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/JKDOM.SVG/300px-JKDOM.SVG.png" alt="" class="thumbimage" width="300" border="0" height="400"></a>
<div class="thumbcaption">
<div class="magnify"><a  href="http://en.wikipedia.org/wiki/File:JKDOM.SVG" class="internal" title="Enlarge"><img  src="http://en.wikipedia.org/skins-1.5/common/images/magnify-clip.png" alt="" width="15" height="11"></a></div>
Hierarchy of objects in an example HTML DOM - Document Object Model</div>
</div>
</div>
<p>The <strong>Document Object Model</strong> (<strong>DOM</strong>) is a <a  href="http://en.wikipedia.org/wiki/Cross-platform" title="Cross-platform">cross-platform</a> and <a  href="http://en.wikipedia.org/wiki/Programming_language" title="Programming language">language</a>-independent convention for representing and interacting with <a  href="http://en.wikipedia.org/wiki/Object_%28computer_science%29" title="Object (computer science)">objects</a> in <a  href="http://en.wikipedia.org/wiki/HTML" title="HTML">HTML</a>, <a  href="http://en.wikipedia.org/wiki/XHTML" title="XHTML">XHTML</a> and <a  href="http://en.wikipedia.org/wiki/XML" title="XML">XML</a>
documents. Objects under the DOM (also sometimes called "Elements") may
be specified and addressed according to the syntax and rules of the
programming language used to manipulate them. The rules for programming
and interacting with the DOM are specified in the DOM <a  href="http://en.wikipedia.org/wiki/Application_Programming_Interface" title="Application programming interface" class="mw-redirect">Application Programming Interface</a> (API).</p>
<table id="toc" class="toc" summary="Contents">
    <tbody>
        <tr>
            <td>
            <div id="toctitle">
            <h2>Contents</h2>
            <span class="toctoggle">[<a  href="javascript:toggleToc()" class="internal" id="togglelink">hide</a>]</span></div>
            <ul>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#History"><span class="tocnumber">1</span> <span class="toctext">History</span></a>
                <ul>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Legacy_DOM"><span class="tocnumber">1.1</span> <span class="toctext">Legacy DOM</span></a></li>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Intermediate_DOM"><span class="tocnumber">1.2</span> <span class="toctext">Intermediate DOM</span></a></li>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Standardization"><span class="tocnumber">1.3</span> <span class="toctext">Standardization</span></a></li>
                </ul>
                </li>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Applications"><span class="tocnumber">2</span> <span class="toctext">Applications</span></a>
                <ul>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Web_browsers"><span class="tocnumber">2.1</span> <span class="toctext">Web browsers</span></a></li>
                </ul>
                </li>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Implementations"><span class="tocnumber">3</span> <span class="toctext">Implementations</span></a>
                <ul>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Layout_engines"><span class="tocnumber">3.1</span> <span class="toctext">Layout engines</span></a></li>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Libraries"><span class="tocnumber">3.2</span> <span class="toctext">Libraries</span></a></li>
                </ul>
                </li>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#See_also"><span class="tocnumber">4</span> <span class="toctext">See also</span></a></li>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#References"><span class="tocnumber">5</span> <span class="toctext">References</span></a></li>
                <li class="toclevel-1"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#External_links"><span class="tocnumber">6</span> <span class="toctext">External links</span></a>
                <ul>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Specifications"><span class="tocnumber">6.1</span> <span class="toctext">Specifications</span></a></li>
                    <li class="toclevel-2"><a  href="http://en.wikipedia.org/wiki/Document_Object_Model#Bindings"><span class="tocnumber">6.2</span> <span class="toctext">Bindings</span></a></li>
                </ul>
                </li>
            </ul>
            </td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
//<![cdata[
if (window.showtoctoggle) { var tocshowtext =" "show";" var tochidetext =" "hide";" showTocToggle(); }
//]]&gt;
</script>
<p><a name="History" id="History"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=1" title="Edit section: History">edit</a>]</span> <span class="mw-headline">History</span></h2>
<p>The history of the Document Object Model is intertwined with the history of the "<a  href="http://en.wikipedia.org/wiki/Browser_wars" title="Browser wars">browser wars</a>" of the late 1990s between <a  href="http://en.wikipedia.org/wiki/Netscape_Navigator" title="Netscape Navigator">Netscape Navigator</a> and <a  href="http://en.wikipedia.org/wiki/Microsoft_Internet_Explorer" title="Microsoft internet explorer" class="mw-redirect">Microsoft Internet Explorer</a>, likewise that of <a  href="http://en.wikipedia.org/wiki/JavaScript" title="JavaScript">JavaScript</a> and <a  href="http://en.wikipedia.org/wiki/JScript" title="JScript">JScript</a>, the first <a  href="http://en.wikipedia.org/wiki/Scripting_language" title="Scripting language">scripting languages</a> to be widely implemented in the <a  href="http://en.wikipedia.org/wiki/Layout_engines" title="Layout engines" class="mw-redirect">layout engines</a> of <a  href="http://en.wikipedia.org/wiki/Web_browsers" title="Web browsers" class="mw-redirect">web browsers</a>.</p>
<p><a name="Legacy_DOM" id="Legacy_DOM"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=2" title="Edit section: Legacy DOM">edit</a>]</span> <span class="mw-headline">Legacy DOM</span></h3>
<p>JavaScript was released by <a  href="http://en.wikipedia.org/wiki/Netscape_Communications" title="Netscape communications" class="mw-redirect">Netscape Communications</a> in 1996 within Netscape Navigator 2.0. Netscape's competitor, <a  href="http://en.wikipedia.org/wiki/Microsoft" title="Microsoft">Microsoft</a>, released Internet Explorer 3.0 later the same year with a <a  href="http://en.wikipedia.org/wiki/Port_%28software%29" title="Port (software)" class="mw-redirect">port</a> of JavaScript called JScript. JavaScript and JScript let <a  href="http://en.wikipedia.org/wiki/Web_developer" title="Web developer">web developers</a> create web pages with <a  href="http://en.wikipedia.org/wiki/Client-side" title="Client-side">client-side</a> interactivity. The limited facilities for detecting user-generated <a  href="http://en.wikipedia.org/wiki/Event_%28computing%29" title="Event (computing)">events</a>
and modifying the HTML document in the first generation of these
languages eventually became known as "DOM Level 0" or "Legacy DOM". No
independent standard was developed for DOM Level 0, but it was partly
described in the specification of <a  href="http://en.wikipedia.org/wiki/HTML4" title="HTML4" class="mw-redirect">HTML4</a>.</p>
<p>Legacy DOM was limited in the kinds of <a  href="http://en.wikipedia.org/wiki/HTML_element" title="HTML element">elements</a> that could be accessed. <a  href="http://en.wikipedia.org/wiki/Form_%28web%29" title="Form (web)">Form</a>, <a  href="http://en.wikipedia.org/wiki/Hyperlink" title="Hyperlink">link</a>
and image elements could be referenced with a hierarchical name that
began with the root document object. A hierarchical name could make use
of either the names or the sequential index of the traversed elements.
For example, a <a  href="http://en.wikipedia.org/wiki/Text_box" title="Text box">form input element</a> could be accessed as either "document.formName.inputName" or "document.forms[0].elements[0]".</p>
<p>The Legacy DOM enabled client-side form validation and the popular "<a  href="http://en.wikipedia.org/wiki/Rollover_%28web_design%29" title="Rollover (web design)">rollover</a>" effect.</p>
<p><a name="Intermediate_DOM" id="Intermediate_DOM"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=3" title="Edit section: Intermediate DOM">edit</a>]</span> <span class="mw-headline">Intermediate DOM</span></h3>
<p>In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer, adding support for <a  href="http://en.wikipedia.org/wiki/Dynamic_HTML" title="Dynamic HTML">Dynamic HTML</a>
(DHTML), functionality enabling changes to a loaded HTML document.
DHTML required extensions to the rudimentary document object that was
available in the Legacy DOM implementations. Although the Legacy DOM
implementations were largely compatible since JScript was based on
JavaScript, the DHTML DOM extensions were developed in parallel by each
browser maker and remained incompatible. These versions of the DOM
became known as the "Intermediate DOM."</p>
<p>The Intermediate DOMs enabled the manipulation of <a  href="http://en.wikipedia.org/wiki/Cascading_Style_Sheet" title="Cascading style sheet" class="mw-redirect">Cascading Style Sheet</a>
(CSS) properties which influence the display of a document. They also
provided access to a new feature called "layers" via the
"document.layers" property (Netscape Navigator) and the "document.all"
property (Internet Explorer). Because of the fundamental
incompatibilities in the Intermediate DOMs, <a  href="http://en.wikipedia.org/wiki/Cross-browser" title="Cross-browser">cross-browser</a> development required special handling for each supported browser.</p>
<p>Subsequent versions of Netscape Navigator abandoned support for its
Intermediate DOM. Internet Explorer continues to support its
Intermediate DOM for <a  href="http://en.wikipedia.org/wiki/Backwards_compatibility" title="Backwards compatibility" class="mw-redirect">backwards compatibility</a>.</p>
<p><a name="Standardization" id="Standardization"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=4" title="Edit section: Standardization">edit</a>]</span> <span class="mw-headline">Standardization</span></h3>
<p>The <a  href="http://en.wikipedia.org/wiki/World_Wide_Web_Consortium" title="World Wide Web Consortium">World Wide Web Consortium</a> (W3C), founded in 1994 to promote <a  href="http://en.wikipedia.org/wiki/Open_standards" title="Open standards" class="mw-redirect">open standards</a> for the <a  href="http://en.wikipedia.org/wiki/World_Wide_Web" title="World Wide Web">World Wide Web</a>,
brought Netscape Communications and Microsoft together with other
companies to develop a standard for browser scripting languages, called
"<a  href="http://en.wikipedia.org/wiki/ECMAScript" title="ECMAScript">ECMAScript</a>".
The first version of the standard was published in 1997. Subsequent
releases of JavaScript and JScript would implement the ECMAScript
standard for greater cross-browser compatibility.</p>
<p>After the release of ECMAScript, W3C began work on a standardized
DOM. The initial DOM standard, known as "DOM Level 1," was recommended
by W3C in late 1998. About the same time, Internet Explorer 5.0 shipped
with limited support for DOM Level 1. DOM Level 1 provided a complete
model for an entire HTML or <a  href="http://en.wikipedia.org/wiki/XML" title="XML">XML</a>
document, including means to change any portion of the document.
Non-conformant browsers such as Internet Explorer 4.x and Netscape 4.x
were still widely used as late as 2000.</p>
<p>DOM Level 2 was published in late 2000. It introduced the "getElementById" function as well as an <a  href="http://en.wikipedia.org/wiki/DOM_Events" title="DOM events" class="mw-redirect">event model</a> and support for <a  href="http://en.wikipedia.org/wiki/XML_namespaces" title="XML namespaces" class="mw-redirect">XML namespaces</a> and CSS. DOM Level 3, the current release of the DOM specification, published in April 2004, added support for <a  href="http://en.wikipedia.org/wiki/XPath" title="XPath">XPath</a> and keyboard <a  href="http://en.wikipedia.org/wiki/Event_handling" title="Event handling" class="mw-redirect">event handling</a>, as well as an interface for <a  href="http://en.wikipedia.org/wiki/Serialization" title="Serialization">serializing</a> documents as XML.</p>
<p>By 2005, large parts of W3C DOM were well-supported by common
ECMAScript-enabled browsers, including Microsoft Internet Explorer
version 6 (2001), <a  href="http://en.wikipedia.org/wiki/Gecko_%28layout_engine%29" title="Gecko (layout engine)">Gecko</a>-based browsers (like <a  href="http://en.wikipedia.org/wiki/Mozilla_Application_Suite" title="Mozilla Application Suite">Mozilla</a>, <a  href="http://en.wikipedia.org/wiki/Mozilla_Firefox" title="Mozilla Firefox">Firefox</a> and <a  href="http://en.wikipedia.org/wiki/Camino" title="Camino">Camino</a>), <a  href="http://en.wikipedia.org/wiki/Konqueror" title="Konqueror">Konqueror</a>, <a  href="http://en.wikipedia.org/wiki/Opera_%28web_browser%29" title="Opera (web browser)">Opera</a>, and <a  href="http://en.wikipedia.org/wiki/Safari_%28web_browser%29" title="Safari (web browser)">Safari</a>.</p>
<p><a name="Applications" id="Applications"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=5" title="Edit section: Applications">edit</a>]</span> <span class="mw-headline">Applications</span></h2>
<p>DOM is likely to be best suited for applications where the document
must be accessed repeatedly or out of sequence order. If the
application is strictly sequential and <a  href="http://en.wikipedia.org/wiki/One-pass_algorithm" title="One-pass algorithm">one-pass</a>, the <a  href="http://en.wikipedia.org/wiki/Simple_API_for_XML" title="Simple API for XML">SAX</a> model is likely to be faster and use less memory. In addition, non-extractive XML parsing models, such as <a  href="http://en.wikipedia.org/wiki/VTD-XML" title="VTD-XML">VTD-XML</a>, provide a new memory-efficient option.</p>
<p><a name="Web_browsers" id="Web_browsers"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=6" title="Edit section: Web browsers">edit</a>]</span> <span class="mw-headline">Web browsers</span></h3>
<p>A web browser is not obliged to use DOM in order to render an HTML
document. However, the DOM is required by JavaScript scripts that wish
to inspect or modify a web page dynamically. In other words, the
Document Object Model is the way JavaScript sees its containing HTML
page and browser state.</p>
<p><a name="Implementations" id="Implementations"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=7" title="Edit section: Implementations">edit</a>]</span> <span class="mw-headline">Implementations</span></h2>
<p>Because DOM supports navigation in any direction (e.g., parent and
previous sibling) and allows for arbitrary modifications, an
implementation must at least buffer the document that has been read so
far (or some parsed form of it).</p>
<p><a name="Layout_engines" id="Layout_engines"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=8" title="Edit section: Layout engines">edit</a>]</span> <span class="mw-headline">Layout engines</span></h3>
<p>Web browsers rely on layout engines to parse HTML into a DOM. Some layout engines such as <a  href="http://en.wikipedia.org/wiki/Gecko_%28layout_engine%29" title="Gecko (layout engine)">Gecko</a> or <a  href="http://en.wikipedia.org/wiki/Trident_%28layout_engine%29" title="Trident (layout engine)">Trident/MSHTML</a> are associated primarily or exclusively with a particular browser such as Firefox or Internet Explorer. Others, such as <a  href="http://en.wikipedia.org/wiki/WebKit" title="WebKit">WebKit</a>, are shared by a number of browsers, such as <a  href="http://en.wikipedia.org/wiki/Safari_%28web_browser%29" title="Safari (web browser)">Safari</a> and <a  href="http://en.wikipedia.org/wiki/Google_Chrome" title="Google Chrome">Google Chrome</a>. The different layout engines implement the DOM standards to varying degrees of compliance.</p>
<div class="rellink boilerplate seealso">See also: <a  href="http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28Document_Object_Model%29" title="Comparison of layout engines (Document Object Model)">Comparison of layout engines (Document Object Model)</a></div>
<p><a name="Libraries" id="Libraries"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=9" title="Edit section: Libraries">edit</a>]</span> <span class="mw-headline">Libraries</span></h3>
<ul>
    <li><a  href="http://en.wikipedia.org/wiki/Java_API_for_XML_Processing" title="Java API for XML Processing">JAXP</a> (Java API for XML Processing)</li>
    <li><a  href="http://en.wikipedia.org/wiki/Libxml2" title="Libxml2">libxml2</a></li>
    <li><a  href="http://en.wikipedia.org/wiki/MSXML" title="MSXML">MSXML</a></li>
    <li><a  href="http://en.wikipedia.org/wiki/VTD-XML" title="VTD-XML">VTD-XML</a> for building SOA intermediary applications</li>
    <li><a  href="http://en.wikipedia.org/wiki/Xerces" title="Xerces">Xerces</a></li>
</ul>
<p><a name="See_also" id="See_also"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=10" title="Edit section: See also">edit</a>]</span> <span class="mw-headline">See also</span></h2>
<ul>
    <li><a  href="http://en.wikipedia.org/wiki/DOM_scripting" title="DOM scripting">DOM scripting</a></li>
    <li><a  href="http://en.wikipedia.org/wiki/JDOM" title="JDOM">JDOM</a> - a Java-based document object model for XML that integrates with DOM and <a  href="http://en.wikipedia.org/wiki/Simple_API_for_XML" title="Simple API for XML">SAX</a> and uses parsers to build the document.</li>
    <li><a  href="http://en.wikipedia.org/wiki/SXML" title="SXML">SXML</a> - a model for representing XML and HTML in the form of S-expressions.</li>
    <li><a  href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" title="Ajax (programming)">Ajax</a> - a methodology employing DOM in combination with techniques for retrieving data without reloading a page.</li>
    <li><a  href="http://en.wikipedia.org/wiki/TinyXml" title="TinyXml" class="mw-redirect">TinyXml</a> - efficient platform-independent XML library for C++.</li>
</ul>
<p><a name="References" id="References"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=11" title="Edit section: References">edit</a>]</span> <span class="mw-headline">References</span></h2>
<ul>
    <li><cite style="font-style: normal;" class="book" id="CITEREFFlanagan2009">Flanagan, David (2006). <em>JavaScript: The Definitive Guide</em>. O'Reilly &amp; Associates. pp.&nbsp;312-313. <a  href="http://en.wikipedia.org/wiki/Special:BookSources/0596101996" class="internal">ISBN 0596101996</a>.</cite><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=JavaScript%3A+The+Definitive+Guide&amp;rft.aulast=Flanagan&amp;rft.aufirst=David&amp;rft.au=Flanagan%2C+David&amp;rft.date=2006&amp;rft.pages=pp.%26nbsp%3B312-313&amp;rft.pub=O%27Reilly+%26+Associates&amp;rft.isbn=0596101996&amp;rfr_id=info:sid/en.wikipedia.org:Document_Object_Model"><span style="display: none;">&nbsp;</span></span></li>
    <li><cite style="font-style: normal;" class="web" id="CITEREFKoch2001">Koch, Peter-Paul (May 14, 2001). <a  href="http://www.digital-web.com/articles/the_document_object_model/" class="external text" title="http://www.digital-web.com/articles/the_document_object_model/" rel="nofollow">"The Document Object Model: an Introduction"</a>. <em>Digital Web Magazine</em><span class="printonly">. <a  href="http://www.digital-web.com/articles/the_document_object_model/" class="external free" title="http://www.digital-web.com/articles/the_document_object_model/" rel="nofollow">http://www.digital-web.com/articles/the_document_object_model/</a></span><span class="reference-accessdate">. Retrieved on January 10, 2009</span>.</cite><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.btitle=The+Document+Object+Model%3A+an+Introduction&amp;rft.atitle=Digital+Web+Magazine&amp;rft.aulast=Koch&amp;rft.aufirst=Peter-Paul&amp;rft.au=Koch%2C+Peter-Paul&amp;rft.date=May+14%2C+2001&amp;rft_id=http%3A%2F%2Fwww.digital-web.com%2Farticles%2Fthe_document_object_model%2F&amp;rfr_id=info:sid/en.wikipedia.org:Document_Object_Model"><span style="display: none;">&nbsp;</span></span></li>
    <li><cite style="font-style: normal;" class="web" id="CITEREFLe_H.C3.A9garet2009">Le H&#233;garet, Philippe (2002). <a  href="http://www.w3.org/2002/07/26-dom-article.html" class="external text" title="http://www.w3.org/2002/07/26-dom-article.html" rel="nofollow">"The W3C Document Object Model (DOM)"</a>. World Wide Web Consortium<span class="printonly">. <a  href="http://www.w3.org/2002/07/26-dom-article.html" class="external free" title="http://www.w3.org/2002/07/26-dom-article.html" rel="nofollow">http://www.w3.org/2002/07/26-dom-article.html</a></span><span class="reference-accessdate">. Retrieved on January 10, 2009</span>.</cite><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.btitle=The+W3C+Document+Object+Model+%28DOM%29&amp;rft.atitle=&amp;rft.aulast=Le+H%C3%A9garet&amp;rft.aufirst=Philippe&amp;rft.au=Le+H%C3%A9garet%2C+Philippe&amp;rft.date=2002&amp;rft.pub=World+Wide+Web+Consortium&amp;rft_id=http%3A%2F%2Fwww.w3.org%2F2002%2F07%2F26-dom-article.html&amp;rfr_id=info:sid/en.wikipedia.org:Document_Object_Model"><span style="display: none;">&nbsp;</span></span></li>
    <li><cite style="font-style: normal;" class="web" id="CITEREFGuisset">Guisset, Fabian. <a  href="http://developer.mozilla.org/en/docs/DOM_Levels" class="external text" title="http://developer.mozilla.org/en/docs/DOM_Levels" rel="nofollow">"What does each DOM Level bring?"</a>. <em>Mozilla Developer Center</em>. Mozilla Project<span class="printonly">. <a  href="http://developer.mozilla.org/en/docs/DOM_Levels" class="external free" title="http://developer.mozilla.org/en/docs/DOM_Levels" rel="nofollow">http://developer.mozilla.org/en/docs/DOM_Levels</a></span><span class="reference-accessdate">. Retrieved on January 10, 2009</span>.</cite><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.btitle=What+does+each+DOM+Level+bring%3F&amp;rft.atitle=Mozilla+Developer+Center&amp;rft.aulast=Guisset&amp;rft.aufirst=Fabian&amp;rft.au=Guisset%2C+Fabian&amp;rft.pub=Mozilla+Project&amp;rft_id=http%3A%2F%2Fdeveloper.mozilla.org%2Fen%2Fdocs%2FDOM_Levels&amp;rfr_id=info:sid/en.wikipedia.org:Document_Object_Model"><span style="display: none;">&nbsp;</span></span></li>
</ul>
<p><a name="External_links" id="External_links"></a></p>
<h2><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=12" title="Edit section: External links">edit</a>]</span> <span class="mw-headline">External links</span></h2>
<table class="metadata plainlinks mbox-small" style="border: 1px solid #aaaaaa; background-color: #f9f9f9;">
    <tbody>
        <tr>
            <td class="mbox-image"><a  href="http://commons.wikimedia.org/wiki/Special:Search/Document_Object_Model" title="commons:Special:Search/Document Object Model"><img  src="http://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Commons-logo.svg/40px-Commons-logo.svg.png" alt="Sister project" width="40" border="0" height="54"></a></td>
            <td class="mbox-text"><a  href="http://en.wikipedia.org/wiki/Wikimedia_Commons" title="Wikimedia Commons">Wikimedia Commons</a> has media related to: <strong><em><a  href="http://commons.wikimedia.org/wiki/Category:Document_object_models" class="extiw" title="commons:Category:Document object models"><br>
            Document object models</a> </em></strong></td>
        </tr>
    </tbody>
</table>
<ul>
    <li><a  href="http://www.w3.org/DOM/" class="external text" title="http://www.w3.org/DOM/" rel="nofollow">W3.org on DOM</a></li>
    <li><a  href="http://xml.coverpages.org/dom.html" class="external text" title="http://xml.coverpages.org/dom.html" rel="nofollow">Technology Reports</a></li>
    <li><a  href="http://xml.com/pub/rg/DOM_Tutorials" class="external text" title="http://xml.com/pub/rg/DOM_Tutorials" rel="nofollow">Tutorials</a></li>
    <li><a  href="http://www.w3.org/2003/02/06-dom-support.html" class="external text" title="http://www.w3.org/2003/02/06-dom-support.html" rel="nofollow">What does your user agent claim to support?</a></li>
    <li><a  href="http://www.quirksmode.org/dom/contents.html" class="external text" title="http://www.quirksmode.org/dom/contents.html" rel="nofollow">W3C DOM scripts and compatibility tables</a> (Quirksmode)</li>
    <li><a  href="http://developer.mozilla.org/en/Gecko_DOM_Reference" class="external text" title="http://developer.mozilla.org/en/Gecko_DOM_Reference" rel="nofollow">Gecko DOM Reference</a> (Mozilla Developer Center)</li>
    <li><a  href="https://studio.tellme.com/dom/ref/" class="external text" title="https://studio.tellme.com/dom/ref/" rel="nofollow">DOM Reference</a> (Tellme)</li>
    <li><a  href="http://ibdom.sourceforge.net/" class="external text" title="http://ibdom.sourceforge.net/" rel="nofollow">IB DOM Utilities: Mapping JavaScript Objects to DOM Elements</a></li>
</ul>
<p><a name="Specifications" id="Specifications"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=13" title="Edit section: Specifications">edit</a>]</span> <span class="mw-headline">Specifications</span></h3>
<ul>
    <li><a  href="http://www.w3.org/TR/REC-DOM-Level-1/" class="external text" title="http://www.w3.org/TR/REC-DOM-Level-1/" rel="nofollow">Document Object Model (DOM) Level 1 Specification</a></li>
    <li>Level 2 Recommendations:
    <ul>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-Core/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-Core/" rel="nofollow">Document Object Model (DOM) Level 2 Core Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-Views/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-Views/" rel="nofollow">Document Object Model (DOM) Level 2 Views Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-Events/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-Events/" rel="nofollow">Document Object Model (DOM) Level 2 Events Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-Style/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-Style/" rel="nofollow">Document Object Model (DOM) Level 2 Style Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/" rel="nofollow">Document Object Model (DOM) Level 2 Traversal and Range Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-2-HTML/" class="external text" title="http://www.w3.org/TR/DOM-Level-2-HTML/" rel="nofollow">Document Object Model (DOM) Level 2 HTML Specification</a></li>
    </ul>
    </li>
    <li>Level 3 Recommendations:
    <ul>
        <li><a  href="http://www.w3.org/TR/DOM-Level-3-Core/" class="external text" title="http://www.w3.org/TR/DOM-Level-3-Core/" rel="nofollow">Document Object Model (DOM) Level 3 Core Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-3-LS/" class="external text" title="http://www.w3.org/TR/DOM-Level-3-LS/" rel="nofollow">Document Object Model (DOM) Level 3 Load and Save Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-3-Val/" class="external text" title="http://www.w3.org/TR/DOM-Level-3-Val/" rel="nofollow">Document Object Model (DOM) Level 3 Validation Specification</a></li>
    </ul>
    </li>
    <li>Level 3 Working Group Notes:
    <ul>
        <li><a  href="http://www.w3.org/TR/DOM-Level-3-XPath/" class="external text" title="http://www.w3.org/TR/DOM-Level-3-XPath/" rel="nofollow">Document Object Model (DOM) Level 3 XPath Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Level-3-Views/" class="external text" title="http://www.w3.org/TR/DOM-Level-3-Views/" rel="nofollow">Document Object Model (DOM) Level 3 Views and Formatting Specification</a></li>
        <li><a  href="http://www.w3.org/TR/DOM-Requirements/" class="external text" title="http://www.w3.org/TR/DOM-Requirements/" rel="nofollow">Document Object Model (DOM) Requirements</a></li>
    </ul>
    </li>
    <li>Working Draft
    <ul>
        <li><a  href="http://www.w3.org/TR/Window/" class="external text" title="http://www.w3.org/TR/Window/" rel="nofollow">Window Object 1.0</a></li>
    </ul>
    </li>
</ul>
<p><a name="Bindings" id="Bindings"></a></p>
<h3><span class="editsection">[<a  href="http://en.wikipedia.org/w/index.php?title=Document_Object_Model&amp;action=edit&amp;section=14" title="Edit section: Bindings">edit</a>]</span> <span class="mw-headline">Bindings</span></h3>
<ul>
    <li><a  href="https://libre.adacore.com/xmlada/" class="external text" title="https://libre.adacore.com/xmlada/" rel="nofollow">Ada</a></li>
    <li><a  href="http://gdome2.cs.unibo.it/" class="external text" title="http://gdome2.cs.unibo.it/" rel="nofollow">C</a></li>
    <li>C++: <a  href="http://www.jezuk.co.uk/cgi-bin/view/arabica" class="external text" title="http://www.jezuk.co.uk/cgi-bin/view/arabica" rel="nofollow">Arabica</a>, <a  href="http://xerces.apache.org/xerces-c/ApacheDOMC++Binding.html" class="external text" title="http://xerces.apache.org/xerces-c/ApacheDOMC++Binding.html" rel="nofollow">Xerces</a></li>
    <li>Common Lisp: <a  href="http://interaction.in-progress.com/developer/dom/" class="external text" title="http://interaction.in-progress.com/developer/dom/" rel="nofollow">XPublish</a>, <a  href="http://www.cliki.net/CL-XML" class="external text" title="http://www.cliki.net/CL-XML" rel="nofollow">CL-XML</a>, <a  href="http://www.cliki.net/CXML" class="external text" title="http://www.cliki.net/CXML" rel="nofollow">CXML</a></li>
    <li><a  href="http://www.fh-wedel.de/%7Esi/HXmlToolbox/" class="external text" title="http://www.fh-wedel.de/~si/HXmlToolbox/" rel="nofollow">Haskell</a></li>
    <li><a  href="http://www.w3.org/2003/01/dom2-javadoc/index.html" class="external text" title="http://www.w3.org/2003/01/dom2-javadoc/index.html" rel="nofollow">Java</a> - W3C Document Object Model Level 2</li>
    <li><a  href="http://www.philo.de/xml/downloads.shtml" class="external text" title="http://www.philo.de/xml/downloads.shtml" rel="nofollow">Pascal</a> (<a  href="http://en.wikipedia.org/wiki/Kylix_programming_tool" title="Kylix programming tool" class="mw-redirect">Kylix programming tool</a>)</li>
    <li><a  href="http://search.cpan.org/dist/XML-LibXML/lib/XML/LibXML/DOM.pod" class="external text" title="http://search.cpan.org/dist/XML-LibXML/lib/XML/LibXML/DOM.pod" rel="nofollow">Perl</a></li>
    <li><a  href="http://www.php.net/dom/" class="external text" title="http://www.php.net/dom/" rel="nofollow">PHP</a></li>
    <li><a  href="http://www.python.org/doc/2.5/lib/module-xml.dom.html" class="external text" title="http://www.python.org/doc/2.5/lib/module-xml.dom.html" rel="nofollow">Python</a></li>
    <li><a  href="http://libgdome-ruby.berlios.de/" class="external text" title="http://libgdome-ruby.berlios.de/" rel="nofollow">Ruby</a></li>
    <li><a  href="http://tclxml.sourceforge.net/tcldom.html" class="external text" title="http://tclxml.sourceforge.net/tcldom.html" rel="nofollow">TCL</a></li>
</ul>
<br><br><img src ="http://www.cppblog.com/beautykingdom/aggbug/80945.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2009-04-24 15:06 <a href="http://www.cppblog.com/beautykingdom/archive/2009/04/24/80945.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Browsers, processes, cookies and session state&lt;forward&gt;</title><link>http://www.cppblog.com/beautykingdom/archive/2009/04/03/78836.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 03 Apr 2009 08:58:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2009/04/03/78836.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/78836.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2009/04/03/78836.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/78836.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/78836.html</trackback:ping><description><![CDATA[Opening the same web page in multiple browser tabs or windows can cause some serious problems if that page relies on cookies or session state. If you're lucky, the problem will be obvious to the user but it's quite possible that they'll be completely unaware of it until after they've corrupted some data. <br>The Problem<br><br>Imagine the user of a web application, viewing details of Object1. The user wants to compare Object1 with Object2 so opens the details of Object2 in a second window or tab. If the application is storing the "current object id" in session state or a cookie then this value will now correspond to Object2. The user then decides to modify Object1's details, so amends them on the page and saves the changes.<br><br>If the application is really badly coded then the save operation could update the record corresponding to the current object id (Object2) with the new details for Object1. Even if it updates the right record, the current id in session state is still wrong - if this id is used to select the data for the next page that the user visits then they will end up with both tabs/windows pointing at Object2.<br><br><strong>Processes</strong><br><br>The problem stems from the fact that multiple tabs and windows can be running in the same process.<br><br>Firefox uses the same process for multiple tabs and, by default, the same process for all windows, whether they are launched from Windows or from each other (Ctrl-N style). <br><br>IE6 managed it's own processes so you could never be entirely certain about when further processes would be created unless you forced the situation using the -new command line switch. The most common situation I've found is that Ctrl-N creates a window using the existing process, Javascript calls (e.g. window.open, window.show...) use the existing process, but launching IE from Windows creates a new process.<br><br>IE7 has abandoned the -new switch, and seems to use a new process for each new window launched from Windows. All tabs within a window, however, run under one process, and spawning windows with Ctrl-N or Javascript commands seems to always re-use the existing process as well. <br>Cookies and Session State<br><br>Sharing a process isn't itself a bad thing. Time and resources can be saved by this approach, but unfortunately a browser's cookies are tied to it's process. If a page is displayed in two tabs or windows running in the same process, then the two instances of the page will share their cookies.<br><br>There are two types of cookie. Persistent cookies are saved to disk and kept until their expiry date. Persistent cookies will always be shared between multiple instances of the same page, regardless of whether the pages are running in the same browser process. If the page creates a persistent cookie called "ObjectID" then this will be stored in a file on disk and will be accessible to any other instance of that same page (unless you use a different browser application - IE and Firefox do not share cookies).<br><br>Session cookies, on the other hand, are kept in memory and are only available until the browser process ends. If two instances of a web application run in two separate processes then there will be two separate session cookies, but if the two instances are in the same process, then they will share the session cookie.<br><br>Furthermore, if the web application is relying on a session cookie to store a session id (the default setup for an ASP.NET web application is to store the ASP.NET_SessionId in a session cookie) then anything in session state will be shared between the two pages: if one of them updates session state then the other will be affected.<br><br><strong>Options</strong><br><br>What this means for a developer is that it is quite possible that your application will have to cope with multiple copies of the same page running in the same process, sharing cookies. Ideally you should be able to have each page running independently of the others, regardless of them sharing a process.<br><br>Normally you can work around the problem by using viewstate. Small objects can be stored directly in viewstate but you shouldn't be sending anything too big down the line to the browser. If your object is more than a simple integer or short string then it will probably be better to generate a GUID and store that in viewstate, using the GUID to access a part of sessionstate which can be kept unique for that instance of the page, regardless of the process-sharing.<br><br>In the example we began with, the current object id could easily be stored in viewstate. If there was an object that needed to be persisted for some reason then it would probably be better off in session state, so the second technique would be better.<br><br>There are times, however, when viewstate doesn't work. In some situations (for example, setting up dynamically generated controls) the current object id may be required in Page_Init, when viewstate is not available. This was actually the situation which lead to us developing an HTA-based intranet (each instance of an HTA has it's own process, so cookies and sessions are never shared), but HTA is not an option for a normal website.<br><br>Probably the best solution, if you're using ASP.NET, is cookieless sessions. In this situation the ASP.NET session id is part of the URL, and is not shared between tabs or windows. This solution works well in the Page_Init situation, but leads to some very unwieldy URLs and has other drawbacks connected to security and absolute linking. It is also an application (or machine) setting, so cannot be used as a last resort only for those few pages that need Page_Init.<br><br><strong>Conclusion</strong><br><br>In general, viewstate is the perfect solution to the problem. Each instance of a page can keep track of its own state, with no interference from other instances.<br><br>When state information is required in Page_Init things get a little more complicated and cookieless sessions are definitely worth considering.<br><br><br><br>Test Code<br><br>A simple page incrementing a counter in session state can be used to demonstrate the problem. Launching new windows with CTRL-N in either browser will default to using the existing process, as will all tabs. <br><br>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br><br>Dim x As Integer<br><br>If IsNothing(Session("test")) Then<br>x = 1234<br>Else<br>x = CInt(Session("test")) + 1<br>End If<br><br>Session("test") = x<br><br>Label1.Text = CInt(Session("test"))<br><br>End Sub<br><br>forwarded by as follows:<br><a href="http://www.cloudward.net/techLife/article.asp?id=1758">http://www.cloudward.net/techLife/article.asp?id=1758</a>
<img src ="http://www.cppblog.com/beautykingdom/aggbug/78836.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2009-04-03 16:58 <a href="http://www.cppblog.com/beautykingdom/archive/2009/04/03/78836.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>