XML and Windows CE 3.0
发表于2003/5/22 8:39:00 766人阅读
XML and Windows CE 3.0
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
XML for Windows CE
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.
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> Bill Williams</NAME>
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:
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:
<ElementType name="NAME" content="textOnly"/>
<ElementType name="EMAIL" content="textOnly"/>
<ElementType name="PHONE" content="textOnly"/>
<ElementType name="CONTACT" content="eltOnly">
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.)
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":
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:
<TABLE BORDER="1" CELLPADDING="1" CELLSPACING="0">
<xsl:for-each select="CONTACTS/CONTACT" order-by="EMAIL">
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:
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");
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”:
var Obj1 = new ActiveXObject("MyCorp.MyComponent");
var y = Obj1.Process(); // Create a new COM object and use it to handle
// additional processing.
Microsoft Windows CE 5.0 Board Support Package, Boot Loader, and Kernel Startup Sequence
jjunjoe 2011-01-13 09:50 762
Windows Phone开发之XML解析和SQL CE数据库之初体验
whuarui2010 2012-06-21 10:04 1671
This node has namespaceId '1902198261 and clusterId 'CID-0ce44319-7032-49ec-83e5-4df0782a0d4e' but t
xiaoshunzi111 2016-02-14 15:45 2602
Windows Embedded CE 6.0 下载地址和序列号
syflyhua 2013-07-03 14:40 719
Windows CE 基础数据库编程(基于EDB)
XJH0918 2016-10-07 12:09 192
Windows Embedded CE 6内核、驱动开发环境搭建
wk2311 2012-02-23 11:23 260
chzhpi_10 2011-11-04 09:21 781
Windows CE USB摄像头驱动编写
whw8007 2013-05-01 21:31 784