XML and Windows CE 3.0

原创 2003年05月22日 08:39:00

XML and Windows CE 3.0

Michael Reeves
Microsoft Corporation

November 2000

Summary: Windows CE 3.0 operating system extends the range of options available to developers by providing a subset of Extensible Markup Language (XML) functionality. This document describes the features of XML that have been incorporated into Windows CE and the differences between using XML on a Windows CE–based platform and on a Windows-based desktop computer. (9 printed pages)


Extensible Markup Language
   Web Services and XML
XML for Windows CE
   Validating Data
   Document Management
   Formatting Complex Data for Presentation
   Instantiation of COM Objects Through XSL


The Microsoft® Windows® CE 3.0 operating system extends the range of options available to developers by providing a subset of Extensible Markup Language (XML) functionality. This document describes the features of XML that have been incorporated into Windows CE and the differences between using XML on a Windows CE–based platform and on a Windows-based desktop computer. For general information about XML, see the documentation available in the MSDN Online Library. (Note that throughout this article, MSXML refers to the XML parser available from Microsoft, and XML refers to the markup language.)

Extensible Markup Language

XML is a meta-markup language that provides a format for describing structured data and allows developers to easily describe and deliver rich, structured data from any application in a standard, consistent way. XML facilitates more precise declarations of content and provides more meaningful search results across multiple platforms. In addition, XML is enabling a new generation of Web-based applications for viewing and manipulating data.

The power and beauty of XML comes from its maintaining the separation of the user interface from the structured data. While Hypertext Markup Language (HTML) tags can display a word in bold face or italics, XML provides a framework for tagging structured data. An XML tag can indicate that the data associated with the tag is a retail price, a sales tax, a book title, an amount of precipitation, or any other desired data. As XML tags are adopted by organizations for their intranets, and by others across the Internet, the ability to search for and manipulate data, regardless of the applications within which the data resides, will increase. Once an application locates XML data, the application can deliver the data over the network and present the data in a Web browser (such as Microsoft® Internet Explorer) in any number of ways, or the application can hand off the data to other applications for further processing and viewing.

XML, which provides a data standard that can encode the content, semantics, and schemata for a wide variety of cases ranging from simple to complex, can be used to mark up the following:

  • An ordinary document
  • A structured record, such as an appointment record or purchase order
  • An object with data and methods, such as the persistent form of a Java object or ActiveX® control
  • A data record, such as the result set of a query
  • Metacontent about a Web site, such as Channel Definition Format (CDF)
  • A graphical presentation, such as an application's user interface
  • Standard schema entities and types
  • All links between information and people on the Web

Once the data is on the client desktop, it can be manipulated, edited, and presented in multiple views without return trips to the server. Servers can now become more scalable, due to lower computational and bandwidth loads. Also, because data is exchanged in the XML format, it can be easily merged from different sources.


Web Services and XML

Unlike current component technologies, Web services do not use object-model-specific protocols such as Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), or Internet Inter-ORB Protocol (IIOP) that require specific, homogeneous infrastructures on both the client and service machines. While implementations tightly coupled to specific component technologies are perfectly acceptable in a controlled environment, they become impractical on the Web. As the set of participants in an integrated business process changes, and as technology changes over time, it becomes very difficult to guarantee a single, unified infrastructure among all participants. Web services take a different approach: They communicate using ubiquitous Web protocols and data formats such as Hypertext Transfer Protocol (HTTP) and XML. Any system supporting these Web standards will be able to support Web services.

Furthermore, a Web service contract describes the services provided in terms of the messages the Web service accepts and generates rather than how the service is implemented. By focusing solely on messages, the Web services model is completely independent of the language, platform, and object model used. A Web service can be implemented using the full feature set of any programming language, object model, and platform.

XML is the obvious choice for defining a standard yet extensible language to represent commands and typed data. While rules for representing commands and typed data using other techniques (such as encoding as a query string) could be defined, XML is specifically designed as a standard metalanguage for describing data.

XML is also the enabling technology for Web service contracts. The Service Contract Language (SCL) is an XML grammar for documenting Web service contracts. Because SCL is XML-based, contracts are easy for both developers and developer tools to create and interpret.

For more information about Microsoft Web Services, see The Programmable Web: Web Services Provides Building Blocks for the Microsoft .NET Framework.

XML for Windows CE

Microsoft Windows CE 3.0 supports a subset of MSXML 2.0 functionality. Specifically, Windows CE does not support the following features:

  • Simple data types on attributes
  • Addition of an "id" data type for elements
  • Assignment of data types through element names
  • Data islands
  • Data binding
  • Mime Type viewer
  • Backward compatibility with the Microsoft XML Document Object Model (DOM) supported by Microsoft Internet Explorer 4.0

Also, Windows CE provides only limited XML security.

Some of the MSXML 2.0 features that are supported in Windows CE are:

  • XML validation through schema, namespace, and data type support.
  • The ability to build and manage complex documents and data through Document Object Model (DOM) support.
  • Web browser formatting through Extensible Stylesheet Language (XSL) support.
  • Automated document requests and parsing functions through the use of XMLHTTP features.

Windows CE also supports the ability to instantiate Component Object Model (COM) objects within blocks of an XSL script, which is a feature of MSXML 2.5.

Validating Data

MSXML for Windows CE supports a technical preview release of XML schemata. The XML schema support is a subset of the Worldwide Web Consortium (W3C) XML data submission and is functionally very close to the W3C Document Content Description (DCD) submission.

Consider the following XML file:

        <NAME>Stephanie Smith</NAME>
        <PHONE>(425) 111-1111</PHONE>
        <NAME> Bill Williams</NAME>
        <PHONE>(425) 111-1111</PHONE>
        <NAME>Christopher Jones</NAME>
        <PHONE>(425) 111-1111</PHONE>

With the new XML schema support in MSXML for Windows CE, the above data can be validated against a schema by declaring the following namespace on the root element:

<CONTACTS xmlns="x-schema:contactSchema.xml">

This sets the schema contactSchema.xml as the default namespace for the document. Other namespaces can be declared throughout the document if desired, but, where no namespace is specified, the default will apply.

The complete schema for the above XML document is as follows:

<Schema xmlns="urn:schemas-microsoft-com:xml-data"
<ElementType name="NAME" content="textOnly"/>
<ElementType name="BIRTHDATE"
<ElementType name="EMAIL" content="textOnly"/>
<ElementType name="PHONE" content="textOnly"/>
<ElementType name="CONTACT" content="eltOnly">
   <element type="NAME"/>
   <element type="BIRTHDATE"/>
   <element type="EMAIL"/>
   <element type="PHONE"/>
 <ElementType name="CONTACTS"
   <element type="CONTACT"/>

The attribute:


sets the default namespace for the XML document as the schema namespace. This means that the schema must conform to the syntax for XML schemata. Similarly, the attribute:


declares the data type namespace. This means that data types can now be declared throughout the schema. (Note that the dt prefix on the type attribute is used to type the BIRTHDATE value.)

Document Management

The DOM is a platform-neutral and language-neutral interface that permits scripts to access and update the content, structure, and style of a document. The DOM includes a model for how a standard set of objects representing HTML and XML documents are combined and an interface for accessing and manipulating them. The Microsoft XML Parser on Windows CE has full DOM support in compliance with the W3C DOM recommendation. In addition, it also has the Microsoft extensions that allow access to typed data and namespace information, creation of nodes by node type, and so on. The following is a script that loads an XML document containing the contact information and uses XSL pattern matching to display the phone number of the contact with the name of "Bill Williams":

function showPhone()
    var root = Contacts.documentElement;
    var selectedElems =  root.selectNodes("CONTACT[NAME='Bill Williams']");
    var billElem = selectedElems.item(0);
    var phone = billElem.childNodes.item(3).nodeTypedValue;
    alert("Bill Williams phone number is " + phone);

The selectNodes method uses XSL pattern-matching to retrieve a node list. In this case, the script looks for all CONTACT elements that have a NAME element with the value of "Bill Williams." Because there is only one element that matches this pattern, selectNodes returns a node list of length one.

Formatting Complex Data for Presentation

MSXML on Windows CE also provides support for XSL, which allows for more complex display of XML data. For instance, the previous contact information can be displayed in a simple table format. The first task would be to create an XSL style sheet:

<xsl:stylesheet xmlns:xsl="uri:xsl">
  <xsl:template match="/">
        <TD BGCOLOR="#C0C0C0"><B>Name</B></TD>
        <TD BGCOLOR="#C0C0C0"><B>Phone</B></TD>
        <TD BGCOLOR="#C0C0C0"><B>Email</B></TD>
      <xsl:for-each select="CONTACTS/CONTACT" order-by="EMAIL">
          <TD><I><xsl:value-of select="NAME"/></I></TD>
          <TD><xsl:value-of select="PHONE"/></TD>
          <TD><xsl:value-of select="EMAIL"/></TD>

This particular style sheet creates a table and uses the values of selected XML elements to fill the table with information. The style sheet also sorts the information by e-mail name (using the order-by attribute on the xsl:for-each element). Note that the order in which the contact information is displayed differs from the original XML document.

This style sheet can be applied to the XML document through the XML Object Model, which is a set of application programming interfaces (APIs) that allow interaction with the elements of the XML structured tree. The transformNode method on IXMLDOMNode passes in an XSL tree and uses that tree to transform an XML node into an output string. In the following case, that string will be an HTML string that gets inserted into the current document:

function showContacts()

The above script displays the following in the browser:


Using the XMLHTTP object, the XML tree itself can be posted as an object. In the following script, an XMLHTTP object is created and posts an XML tree named "template" to the server location:

var httpOb = new ActiveXObject("Microsoft.XMLHTTP");
httpOb.Open("POST","http://myServer/postContact.asp", false);
var contact = template.XMLDocument.documentElement;
contact.childNodes.item(0).text = contactName.value;
contact.childNodes.item(1).text = contactPhone.value;
contact.childNodes.item(2).text = contactEmail.value;

The XMLHTTP object and its properties are outlined in the IXMLHttpRequest Interface documentation in the MSDN Online Library.

Instantiation of COM Objects Through XSL

Windows CE supports instantiation of COM objects, such as ActiveX controls, through the XSL script interface. The following script demonstrates instantiation of a fictitious COM object, “MyCorp”:

<xsl:script>function TestCOMObject() 
    var Obj1 = new ActiveXObject("MyCorp.MyComponent"); 
    var y = Obj1.Process(); // Create a new COM object and use it to handle
  // additional processing.
    return y; 


Windows CE 3.0 源代码

Windows CE 3.0 源代码  作者:microsoft   来源:biplip    下载>>Microsoft® Windows® CE Platform Builder version ...
  • mobilechannel
  • mobilechannel
  • 2005年02月04日 03:54
  • 2265

Ping-Microsoft Windows CE 3.0

The ping command sends an ICMP echo request to a target name or IP address, helping you to verify IP...
  • jw212
  • jw212
  • 2010年08月05日 11:17
  • 536

《Windows CE 程序设计》第四版

    在Amazon上闲逛,突然发现《Programming Windows CE》(中文译名:《Windows CE 程序设计》)已经出第四版。进行WinCE开发的人,对于 该书相信是熟悉的不能再...
  • norains
  • norains
  • 2007年12月25日 13:20
  • 5625

Windows CE 软件开发入门

MicrosoftWindows CE是紧凑的、高效的和可升级的操作系统,它被广泛的应用在各种嵌入式式的产品中,从手持电脑到专门的工业控制器和消费用电子产品中。Windows CE已经通过了其自身的能...
  • ice197983
  • ice197983
  • 2007年03月29日 16:23
  • 1734

Windows CE 6.0 安装顺序

1、先装Visual Studio 2005, 我拿到的是Professional Edition。最好别用DEFAULT安装,把组件CUSTOM一下,不然会花很多冤枉的磁盘空间。WINCE600的P...
  • kevin_83
  • kevin_83
  • 2007年08月24日 13:33
  • 10058

浅析Windows CE下浏览器源码

  • ark1111
  • ark1111
  • 2004年12月13日 17:43
  • 1024

如何把Windows CE安装文件下载到本地进行安装

今天不讲外挂,说点儿别的。前几天微软为了Windows CE 6.0的发布大张旗鼓,搞了个Virtual Launch Event。本来想着要去凑凑热闹的,结果忙着写外挂文章,给忘了。今天想起来要去下...
  • singlerace
  • singlerace
  • 2006年11月08日 17:59
  • 12604

Microsoft XML Parser (MSXML) 3.0 Service Pack 5 (SP5)

Microsoft® XML Parser (MSXML) 3.0 SP5 版本在以前的 MSXML 3.0 SP 版本的基础上增加了大量安全修补程序和缺陷修补程序。快速信息文件名:msxml3.ms...
  • naxin
  • naxin
  • 2004年11月06日 10:47
  • 7753

Windows CE API大全

1. API之网络函数    WNetAddConnection 创建同一个网络资源的永久性连接   WNetAddConnection2 创建同一个网络资源的连接   WNetAddConnecti...
  • Willjet
  • Willjet
  • 2011年02月12日 10:29
  • 1307

Windows ce的版本

  • hao1983
  • hao1983
  • 2011年02月23日 09:18
  • 3789
您举报文章:XML and Windows CE 3.0