`
javasogo
  • 浏览: 1845871 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Using XML Data Islands in Mozilla(Mozilla中使用XML数据岛)

 
阅读更多

One handy feature of Internet Explorer is the ability to use data islands to link data to html controls on a page. This feature is not readily built into Mozilla, but one can easily mimic this behavior to build cross-browser web applications.

IE有个很灵活的特性,就是能使用数据岛(data islands)把数据绑定到html组件上。这个特性不会马上嵌入到Mozilla,但是有些人可以很容易地跨浏览器模仿这种行为。

The basic data island we are going to use is a simple xml element either linked to the page or explicitly coding the xml into the page. For instance, let us illustrate a simple example:

我们要使用的数据岛是一个连接到页面或直接写在页面中的一个简单的xml元素。例如,下面就是一个简单的例子:

<xml id="xmlDataIsland">
 <loaninfo>
 <borrower id="1">
 <firstname>Brian</firstname>
 <middlename>Ellis</middlename>
 <lastname>Johnson</lastname>
 </borrower>
 </loaninfo>
</xml>

With this data island, we can populate any number of controls on a page simply by linking the data island to the controls via some JavaScript and the DOM.

有了这个数据岛,我们就可以很轻松的使用JavaScriptDOM连接数据岛,来为页面上的组件填充数据了。

To link this, all we need to do is have a function to handle populating the controls such as:

要做连接,我们唯一要做的事就是像下面这样用一个函数来操作组件的数据填充:

function loadFields()
{
 var xmlNode = window.document.getElementsByTagName('xml');
 var borrowerNode = xmlNode[0].childNodes[1];
 if(borrowerNode.hasChildNodes())
 {
 var i = 0;
 var xmlChildNode, nodeVal=;
 while(borrowerNode.childNodes[i])
 {
 // get node
 xmlChildNode = borrowerNode.childNodes[i];
 // check nodetype
 if(xmlChildNode.nodeType!= 3) // #text == 3
 {
 // get nodeValue (aka text)
 nodeVal += xmlChildNode.firstChild.nodeValue + ' ';
 }
 i++;
 }
 // set control value to nodeValue
 window.document.getElementById('txtBorrowerName').value = nodeVal;
 }
}

Example 1

Here is another example of an XML DataIsland for use in Mozilla or IE:

这里是另一个在MozillaIE中使用的XML数据岛的例子:

<xml id="mxxdataisland">
 <mxxdataisland>
 <rowset tagid="DATES"></rowset>
 <rowset tagid="SUBJPRP"></rowset>
 <rowset tagid="PRODUCT"></rowset>
 </mxxdataisland>
</xml>

This dataisland's purpose is to inform the Application Server what tables this page is going to need access to or be requesting information from.

这个数据岛的目的是要通知应用服务器当前页面要访问什么样的表格或是从什么样的表格请求相关信息。

The controls on the page are then linked by way of custom attributes MXXOBJECT and MXXPROPERTY, much like the DATASRC and DATAFLD attributes used by IE. This allows the XML data returned to be parsed and linked or "bound" to the controls.

页面上的组件被自定义的属性MXXOBJECTMXXPROPERTY所连接,很像IE中使用的DATASRCDATAFLD属性。这样就能让返回的XML数据被解析并连接或是“绑定”到组件上。

Note: MXXOBJECT and MXXPROPERTY are just attributes that I made up, these actually could be any attribute.

注意:MXXOBJECTMXXPROPERTY仅仅是我定义的属性,您可以把它们换成其他名称。

Binding the controls:

绑定组件:

<input
 type="text"
 id="PropertyStAddr1"
 name="PropertyStAddr1"
 style="height:21px;width:302px;text-align:left;"
 maxlength="35"
 class="fldDefault"
 mxxobject="SUBJPRP" mxxproperty="PropertyStAddr1" <-- here are our "binding" tags
>

<input
 type="text"
 class="fldZipCode"
 name="PropertyZip"
 id="PropertyZip"
 size="10"
 style="height:21px;width:69px;"
 mxxobject="SUBJPRP" mxxproperty="PropertyZip" <-- here are our "binding" tags
 mxxxmlnode="xmldef_PropertyZip" <-- this links to a control-level data island
 mxxtype="MXXZipCodeAutoLoadEdit" <-- optional custom type for control handling
>

Since we are passing XML to the server, we can also send the server some additional info that a particular control may need, or alert the server of other controls on the page related to or driven by a control. The following is an example of a custom dataisland for a specific control type:

我们可以把XML传递到服务器,同样,我们也可以服务器发送某个特定的控件所需要的额外信息,或是通知相关页面上的其他组件所在的或由组件驱动的服务器。下面是为特定组件定义的一个数据岛的例子。

<select
 id="PropertyState"
 name="PropertyState"
 style="height:20px;width:48px;"
 class="cmbDefault"
 mxxtype="GFXStateList"
 mxxxmlnode="xmldef_PropertyState"
 mxxobject="GOXSUBJPRP" mxxproperty="PropertyState"
>

</select>

<div style="width:0px; height:0px; visibility:hidden;z-index:1">
 <xml id="xmldef_PropertyState">
 <mxxstatelist>
 <status value="initialize"></status>
 <contenttype value="abbrev"></contenttype>
 <controls>
 <control type="countylist" tagid="PropertyCounty" contenttype="name"
 valuetype ="name"></control>
 </controls>
 </mxxstatelist>
 </xml>
</div>

These XMLDataIslands don't do us any good just like this. In order for them to work we need to do 2 things.

这样的数据岛不能为我们带来任何好处。为了能让它们起作用,我们必须做两件事情。

1. Build control handlers to handle the updating and rendering of different control types.

第一,建立组件句柄来控制不同类型的组件的更新与表现。

(Note: Control types can be anything. Form objects, tables, spans, divs, iFrames, anything that you can access via the DOM and an ID is eligible)

(注意:组件类型可以是您通过DOM和有效的ID能够访问的表单对象、表格、spandiviFrame等类型)

2. Build a handler to build a dom to send to the server and parse the return back out to the controls.

建立句柄来创建一个dom并发给服务器,并且分析返到组件的信息。

All a control handler has to do is be able to updata a control value. This means all Text Inputs can share a handler, selects another, and so on. One way to do this is to scrape the controls on a given page into an associative array. Then, when a response is returned, we can parse out the xml via an id attribute to match up the xml payload with a control.

一个组件句柄要做的就是更新组件的值。这就意味着所有的文件输入框可以共享一个句柄,

然后,当响应返回我们可以通过XMLid属性匹配到对应的组件。

<input type="text" id="FirstName" ...>

Sample Object collector function:

简单的队形收集器函数:

 // grab all the elements for parsing
 var tags = window.document.body.getElementsByTagName("*");
 var pPrevElem = null;
 var pNextElem = null;
 for (var i = 0; i < tags.length; i++)
 {
 pHTMLElement = tags[i];

 switch (pHTMLElement.tagName.toLowerCase())
 {
 case "span":
 case "table":
 // this indexes by controlID and stores the elementObject
 m_MXXPageObjectsArray[pHTMLElement.id] = pHTMLElement;
 break;
 case "input":
 case "select":
 case "textarea":
 case "button":
 // this indexes by controlID and stores the elementObject
 m_MXXPageObjectsArray[pHTMLElement.id] = pHTMLElement;
 break;
 case "div":
 // this indexes by controlID and stores the elementObject
 m_MXXPageObjectsArray[pHTMLElement.id] = pHTMLElement;
 break;
 }
 }

The xml payload going out might be:

Xml格式如下:

<page id="NewUser">
 <formcontrols>
 <control id="FirstName">
 <value />
 </control>
 </formcontrols>
</page>

The return would then be:

返回内容如下:

<page id="NewUser">
 <formcontrols>
 <control id="FirstName">
 <value>Dennis</value>
 </control>
 </formcontrols>
</page>

The parsing handler would then take the response, load it into an XML DOM, then pass out each node to the appropriate control handler.

分析句柄接收响应并加载到XML DOM,然后把每个节点传递到对应的组件。

 processTextControl(control, xmlNode);

Sample parsing of returned xml:

返回的xml的简单传递:

 // parseout to controls
 var formControlNodes = xmlDoc.getElementsByTagName('formcontrols');
 for(i=0; i<formControlNodes.length;++i)
 {
 var pFormControlNode = formControlNodes[i];
 var pPageObject = m_MXXPageObjectsArray[pFormControlNode.getAttribute('id')];
 if(!pPageObject)
 continue;
 processTextControl(pPageObject, pBoundControlNode);
 }

The control handler would then rip out the necessary data to populate the control. In this case the value nodevalue would be used to set control.value. A select could have the options to loop through and create new Options() with or even just replace the node or innerHTML with the new payload.

组件句柄将必要的数据填充到相关组件中。这里,节点值将被用于设置组件的值。SELECT标签通过循环遍历来创建OPTION

Here is a sample page.

Finally here is a small table sample using <place w:st="on"><placename w:st="on">XML</placename><placename w:st="on">Data</placename><placetype w:st="on">Islands</placetype></place> that works in both IE6 and Mozilla.

最后,这个是一个在IE6Mozilla里都能运行的XML数据岛的表格例子。

For any of the above to do us any good, we need to get this info to the server. We can do this a number of ways, including ASP, JSP, and CGI. I'm going to use XMLHTTP since it allows for me to update a page without having to reload it and it allows for the controls to update other controls and act like a regular 2 tier application by providing instant updates and event handling.

我们可以用很多方式来实现,包括ASPJSPCGI。我将用XMLHTTP,因为这样可以不重新加载页面来更新页面内容,并且可以像两层应用程序那样,即时更新其他组件和进行事件控制。

Original Document Information

分享到:
评论

相关推荐

    XML分页排序数据岛

    XML数据岛,全称为XML Data Islands,是一种在客户端利用JavaScript和XML进行数据处理的技术,它允许Web页面直接访问和操作嵌入HTML中的XML数据。在本主题“XML分页排序数据岛”中,我们将深入探讨如何利用XML数据岛...

    XML之数据岛

    "XML之数据岛"这个概念,主要指的是在HTML文档中嵌入XML数据的技术,也称为“HTML中的XML数据岛”或“XML Data Islands”。这种技术允许开发者在传统的HTML页面中直接嵌入XML数据,使得页面不仅包含展示信息,还能够...

    Mozilla Firefox 支持数据岛

    数据岛(Data Islands)是一种在网页中嵌入结构化数据的技术,主要通过使用XML数据来增强HTML元素。这种技术使得浏览器可以直接理解和处理嵌入的数据,而无需额外的服务器请求。在【标题】"Mozilla Firefox 支持数据...

    Mozilla Firefox 支持数据岛(第二版)

    数据岛(Data Islands)是一种在HTML中嵌入XML数据的技术,它允许网页开发者将结构化的数据与HTML元素关联,提供了一种在Web页面上展示和操作复杂数据的有效方式。Mozilla Firefox作为一款开源、免费的网络浏览器,...

    Mozilla Firefox 支持数据岛(第三版)

    【标题】"Mozilla Firefox 支持数据岛(第三版)" 指的是 Mozilla Firefox 浏览器对于数据岛(Data Islands)技术的实现与优化。数据岛是一种在HTML文档中嵌入XML数据的方法,允许开发者将结构化数据与网页内容紧密...

    用JSP写的基于数据岛技术的xml购物车 源码

    数据岛技术(Data Islands)指的是在HTML文档中嵌入XML数据,使JavaScript或服务器端脚本可以直接访问和操作这些数据。 3. **数据岛技术**: 数据岛技术允许XML数据直接嵌入到HTML页面中,通过DOM(Document ...

    xml编程ppt数据岛ddt xsl dom jax xml编程 编程编程编程编程编程

    本PPT教程重点讲解了XML在编程中的应用,包括数据岛(Data Islands)、DDT(Data Driven Templates)、XSL(Extensible Stylesheet Language)、DOM(Document Object Model)以及JAXP(Java API for XML Processing...

    Web设计中如何使用XML数据

    初始化DSO后,可以通过XML数据岛(Data Islands)技术将XML数据嵌入HTML文档中。XML数据岛是一个嵌入在HTML页面中的XML片段,可以通过`&lt;XML&gt;`标签定义。然后,通过`datasrc`和`datafld`属性将数据绑定到HTML元素,如...

    XML基础教程与实验指导

    **数据岛(Data Islands)**: 数据岛是将XML数据嵌入到HTML文档中的技术,使网页能够利用XML的数据功能。通过使用脚本语言(如JavaScript)或服务器端技术(如ASP.NET),可以动态地操作这些数据。 **XPath(XML ...

    html.rar_XML通讯录

    在这个名为“html.rar_XML通讯录”的压缩包中,我们可能找到了一个使用XML数据岛(Data Islands)和分布式组件对象模型(DMO)来创建的通讯录应用。 XML数据岛是一种技术,允许在HTML页面中嵌入XML数据,以便于在...

    学习XML基础的课件

    最后,数据岛(Data Islands)可能在课程的某个部分被提及,这是在HTML中嵌入XML数据的技术,使得JavaScript可以更方便地操作和展示数据。 通过这些文档的学习,你将能够创建、解析和操作XML文档,理解如何利用XML...

    xml分页+ajax请求数据源+dom取结果实例代码

    2. **XML数据岛分页显示**:客户端接收到XML数据后,使用数据岛(Data Islands)技术实现分页显示。数据岛是一种将XML数据嵌入HTML文档中的方法,简化了客户端对XML数据的操作。这里利用JavaScript处理XML数据,根据...

    xml基础知识

    7. **数据岛(Data Islands)**:在.NET框架中,数据岛是将XML数据嵌入到HTML文档中的技术,允许动态地将服务器端数据与客户端脚本交互,提高Web应用的响应性。 8. **DTD(Document Type Definition)**:DTD是一种...

    C#课件-XML是一种类似于HTML的标记语言

    XML还允许创建数据岛(Data Islands)嵌入到HTML页面中,使页面能够与后台数据进行交互,而不会破坏页面的布局和显示。此外,XML可以用于存储大量数据,无论是文件还是数据库,都可以方便地进行读取和写入,简化了...

    暴基础的xml复习题

    数据岛(Data Islands)是将XML数据嵌入HTML文档中的一种技术,`&lt;XML&gt;`标记用于链接XML文档。使用HTTP查询并返回XML格式数据时,通常会使用`FOR XML`参数。SVG(Scalable Vector Graphics)是一种用于创建二维矢量...

    解析文件的

    在“0920(jaxb-数据岛)”这个文件中,可能包含的是关于如何使用JAXB来创建和操作数据岛(Data Islands)的教程或者示例代码。数据岛是XML文档中的一段可独立处理的区域,JAXB可以用于高效地读取和写入这些区域,使...

    静态的动态续篇之来点XML

    在HTML中,我们可以使用数据岛(Data Islands)技术将XML数据内联到页面中,以便于JavaScript进行处理。例如,通过以下代码,我们可以在HTML文档中创建一个XML数据岛: ```html &lt;xml id="data"&gt; &lt;!-- 在此为XML...

    vc_xml.rar_xml/soap/webservice_Visual_C++_

    9. **性能优化**:在处理大量XML数据时,考虑使用XML数据岛(XML Data Islands)技术,直接在HTML或XSLT中嵌入XML数据,提高页面加载速度。另外,使用SAX解析器而非DOM,可减少内存消耗。 10. **调试和测试**:使用...

Global site tag (gtag.js) - Google Analytics