News

Monday, July 23, 2007

XML Basics - An Introduction to XML

Introduction to XML by Jan Egil Refsnes
What is XML, and how does it differ from HTML.
 
How XML can be used by Jan Egil Refsnes
Some of the different ways XML can be used.
 
XML Syntax by Jan Egil Refsnes
The syntax rules of XML. How to write well formed XML documents.
 
XML Attributes by Jan Egil Refsnes
How to use attributes to provide additional information about elements.
 
XML Validation - Document Type Definition by Jan Egil Refsnes
Using a DTD is the formal way to describe a valid XML document.
 
XML support in Internet Explorer and Netscape Navigator by Jan Egil Refsnes
About the support for XML in the two most famous browsers.
 
Viewing XML by Jan Egil Refsnes
How to view XML files in your browser.
 
Displaying XML by Jan Egil Refsnes
How to display XML content using JavaScript, CSS or XSL
 
XML Examples by Jan Egil Refsnes
A collection of examples from all the chapters of this Web.
 
XML Links by Jan Egil Refsnes
A collection of useful XML links.
 

Thursday, July 12, 2007

How to add style to XML

The CSS2 Recommendation contains a brief tutorial on using CSS with XML (see § 2.2). At the time CSS2 was written the official specification for style in XML wasn't ready. Here is what that tutorial should have contained. Note that the examples use CSS, but in most cases the style rules can also be written in XSL.
 
External style sheets
 
HTML has a link element to link to external style sheets, but not every XML-based format will have such an element. If there is no suitable element, you can still attach external style sheets by means of the xml-stylesheet processing instruction like this:
 
<?xml-stylesheet href="my-style.css" type="text/css"?>
... rest of document here...
 
This processing instruction (PI) must come before the first tag of the document. The type="text/css" is not required, but it helps the browser: if it doesn't support CSS, it knows it won't have to download this file.
 
Just as with the link element of HTML, there can be multiple xml-stylesheet PIs and they can have attributes to set the type, medium and title.
 
Here is a larger example. Let's assume we have three style sheets, one that sets the basic display type of each element (inline, block, list-item, etc.) and two different ones that each set colors and margins. The two last ones are each other's alternative, and the reader of the document may choose which one to use. Except when the document is printed, in which case we only want to use the last style. Here is the common style sheet:
 
/* common.css */
INSTRUMENT { display: inline }
ARTICLE, HEADLINE, AUTHOR, PARA { display: block }
 
This is one of the alternative styles, in a file called "modern.css":
 
/* modern.css */
ARTICLE { font-family: sans-serif; background: white; color: black }
AUTHOR { margin: 1em; color: red }
HEADLINE { text-align: right; margin-bottom: 2em }
PARA { line-height: 1.5; margin-left: 15% }
INSTRUMENT { color: blue }
 
And here is the other one, called "classic.css":
 
/* classic.css */
ARTICLE { font-family: serif; background: white; color: #003 }
AUTHOR { font-size: large; margin: 1em 0 }
HEADLINE { font-size: x-large; margin-bottom: 1em }
PARA { text-indent: 1em; text-align: justify }
INSTRUMENT { font-style: italic }
 
The XML document with these three style sheets linked to it looks like this:
 
<?xml-stylesheet href="common.css" type="text/css"?>
<?xml-stylesheet href="modern.css" title="Modern" media="screen"
  type="text/css"?>
<?xml-stylesheet href="classic.css" alternate="yes"
  title="Classic" media="screen, print" type="text/css"?>
<ARTICLE>
  <HEADLINE>Fredrick the Great meets Bach</HEADLINE>
  <AUTHOR>Johann Nikolaus Forkel</AUTHOR>
  <PARA>
    One evening, just as he was getting his
    <INSTRUMENT>flute</INSTRUMENT> ready and his
    musicians were assembled, an officer brought him a list of
    the strangers who had arrived.
  </PARA>
</ARTICLE>
 
For more details, see the W3C Recommendation "Associating Style Sheets with XML documents"
 

Tuesday, July 3, 2007

Building Accessible Web Sites with XHTML and CSS Problem Design Solution

  • Shows Web developers how to make the transition from HTML to XHTML, an XML-based reformulation of HTML that offers greater design flexibility
  • Demonstrates how to work with CSS (Cascading Style Sheets)–now supported by ninety percent of browsers and integral to new site-building tools from Macromedia and others–and implement a consistent style throughout and entire site
  • Explains how to make a site accessible to people with impaired vision, limited hand use, dyslexia, and other issues–now a legal requirement for many sites in the U.S. and the U.K.
  • Tuesday, June 26, 2007

    How to install Microsoft XML Parser and Microsoft XML Core Services (MSXML)

    Introduction

    With Microsoft XML Core Services (MSXML), formerly known as the Microsoft XML Parser, customers can build XML-based applications that follow the World Wide Web Consortium (W3C) XML standards. MSXML is a Component Object Model (COM) implementation of the W3C DOM model.
     

    How to install Microsoft XML Parser 3.0

    To install Microsoft XML Parser 3.0, follow these steps:
    1. Check if the operating system meets the requirement to install Microsoft XML Parser 3.0.

    The following operating systems are support by Microsoft XML Parser 3.0:
    Windows 2000
    Windows Server 2003
    Windows XP
    2. Download Microsoft XML Parser 3.0.

    For more information about how to download Microsoft XML Parser 3.0, click the following article number to view the article in the Microsoft Knowledge Base:
    How to obtain the latest Microsoft XML 3.0 service pack
    3. Install Microsoft XML Parser 3.0.
     

    How to install Microsoft XML Core Services 4.0

    To install Microsoft XML Core Services 4.0, follow these steps:
    1. Check if the operating system meets the requirement to install Microsoft XML Core Services 4.0.

    The following operating systems are support by Microsoft XML Core Services 4.0:
    Windows 2000
    Windows Server 2003
    Windows XP
    2. Download Microsoft XML Core Services 4.0.

    For more information about how to download Microsoft XML Core Services 4.0, click the following article number to view the article in the Microsoft Knowledge Base:
    How to obtain the latest Microsoft XML 4.0 service pack
    3. Install Microsoft XML Core Services 4.0.
     

    How to install Microsoft XML Core Services 5.0

    The exact description for MSXML 5.0 is MSXML 5.0 for Microsoft Office Applications. MSXML 5.0 for Microsoft Office Applications is included in Microsoft Office 2003. To install MSXML 5.0 for Microsoft Office Applications, you have to install Office 2003.

     

    How to install Microsoft XML Core Services 6.0

    To install Microsoft XML Core Services 6.0, follow these steps:
    1. Check if the operating system meets the requirement to install Microsoft XML Core Services 6.0.

    The following operating systems are support by Microsoft XML Core Services 4.0:
    Windows 2000 Service Pack 4
    Windows Server 2003
    Windows XP Service Pack 1 and later versions of Windows XP
    2.
    Download Microsoft XML Core Services 6.0.
     

    To download Microsoft XML Core Services 6.0, visit the following Microsoft Web site
    3. Install Microsoft XML Core Services 6.0.

    Tuesday, June 19, 2007

    Programming Microsoft® .NET XML Web Services

    The professional developer's guide to building state-of-the-art XML Web Services with Microsoft .NET
     
    Get the in-depth reference and guidance you need to create and consume high-performance, cross-platform Web solutions in the Microsoft .NET environment. This exhaustive resource cuts to the heart of developing XML Web Services and their clients—offering expert insights on the relevant standards, .NET classes, and key design and development techniques. You'll learn to exploit core technologies such as XML, UDDI, and SOAP, as well as emerging specifications and tools, so that you can create effective and efficient Web Services. You also get complete code in C# for all the book's examples on the Web, ready to adapt to your own applications.

    Discover how to:
    - Use SOAP to communicate with Web Services and WSDL to define them
    - Know when to use DISCO and UDDI for Web services discovery
    - Write XML schemas to specify the content and context of messages sent to and from clients
    - Create Web methods to manage application state, asynchronous calls, and file versioning
    - Build custom clients for Web Service consumption
    - Use Microsoft ADO.NET to expose data from databases, XML files, and servers 
    - Extend the Web Services framework with HTTP modules and SOAP extensions 
    - Use authentication, authorization, SSL connections, cryptography, WS-Security, and other security techniques 
    - Employ Web Service Enhancements (WSE) for attachments, routing, referral, and other advanced functions 
    - Explore Global XML Web Services Architecture (GXA) and other emerging standards

    Wednesday, June 13, 2007

    HOW TO: Validate XML Fragments Against an XML Schema in Visual Basic .NET

    SUMMARY

    This step-by-step article describes how to use XmlValidatingReader and XMLSchemaCollection objects to validate an Extensible Markup Language (XML) fragment against an XML schema.

    XmlValidatingReader implements the XmlReader class and provides support for XML data validation. The Schemas property of XmlValidatingReader connects the reader to the schema files cached in an XmlSchemaCollection. The ValidationType property of XmlValidatingReader specifies the type of validation the reader should perform. If you set the property to ValidationType.None, you create a nonvalidating reader.

    You can only add XML Schema Definition Language (XSD) schemas and XML-Data Reduced (XDR) schemas to XmlSchemaCollection. Use the Add method with a namespace URI to load schemas. For XML schemas, the typical namespace URI is the targetNamespace property of the schema.
     

    Requirements

    The following list outlines the recommended hardware, software, network infrastructure, and service packs that you will need:
    Microsoft Visual Studio .NET installed on a compatible Microsoft Windows operating system
    This article assumes that you are familiar with the following topics:
    Visual Basic .NET
    Basic XML standards
    XSD schemas
     

    Create an XSD Schema

    Paste the following code in a new text file named C:\Books.xsd:
     
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:bookstore-schema" elementFormDefault="qualified" targetNamespace="urn:bookstore-schema">
    <xsd:element name="bookstore" type="bookstoreType" />
    <xsd:element name="comment" type="xsd:string" />
    <xsd:element name="author" type="authorName"/>
    <xsd:complexType name="authorName">
    <xsd:sequence>
    <xsd:element name="first-name" type="xsd:string" />
    <xsd:element name="last-name" type="xsd:string" />
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="bookstoreType">
    <xsd:sequence maxOccurs="unbounded">
    <xsd:element name="book" type="bookType" />
    <xsd:element ref="comment" minOccurs="0" />
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="bookType">
    <xsd:sequence>
    <xsd:element name="title" type="xsd:string" />
    <xsd:element ref="author" />
    <xsd:element name="price" type="xsd:decimal" />
    </xsd:sequence>
    <xsd:attribute name="genre" type="xsd:string" />
    </xsd:complexType>

    </xsd:schema>
     

    Create a Visual Basic .NET Application

    1. Create a new Visual Basic .NET Windows application
     
    2. Drag Button1 to Form1. Paste the following code to add a private member variable to Class Form1:
     
    Dim m_success As Boolean
    3. Paste the following sub procedure to create a ValidationEventHandler that raises validation errors in the XMLValidatingReader object:     
     
    Public Sub ValidationEventHandle(ByVal sender As Object, ByVal args As ValidationEventArgs)
            m_success = False
            Console.WriteLine((ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message))
        End Sub 'ValidationEventHandle
     
    NOTE: You must include an event handler to receive information about validation errors in the Data Type Definition (DTD), the XML-Data Reduced (XDR) schema, and the XML schema definition language (XSD) schema. The event handler receives an argument of type ValidationEventArgs that contains data related to this event.

    The callback handler can use the ValidationEventArgs.Severity property to guarantee that an XML instance document is validated against a schema. The Severity property enables you to distinguish between a validation error (Severity is equal to XmlSeverityType.Error) which indicates a fatal error, and a validation warning (Severity is equal to XmlSeverityType.Warning) which indicates that no schema information is available.
     
    4. Paste the following code in the Button1_Click event procedure:
     
            Dim reader As XmlValidatingReader = Nothing
            Dim myschema As New XmlSchemaCollection()

            Try
                'Create the XML fragment to be parsed.
                Dim xmlFrag As String = "<author  xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" & _
                                "<first-name>Herman</first-name>" & _
                               "<last-name>Melville</last-name>" & _
                             "</author>"

                'Create the XmlParserContext.
                Dim context As New XmlParserContext(Nothing, Nothing, "", XmlSpace.None)
              
                'Implement the reader.
                reader = New XmlValidatingReader(xmlFrag, XmlNodeType.Element, context)
                'Add the schema.
                myschema.Add("urn:bookstore-schema", "Books.xsd")

                'Set the schema type and add the schema to the reader.
                reader.ValidationType = ValidationType.Schema
                reader.Schemas.Add(myschema)

                'Add the handler to raise the validation event.
                AddHandler reader.ValidationEventHandler, AddressOf Me.ValidationEventHandle

                While reader.Read

                End While
                Console.WriteLine("Completed validating xmlfragment")

            Catch XmlExp As XmlException
                Console.WriteLine(XmlExp.Message)
            Catch XmlSchExp As XmlSchemaException
                Console.WriteLine(XmlSchExp.Message)
            Catch GenExp As Exception
                Console.WriteLine(GenExp.Message)
            End Try
        End Sub
     
    5.When the following message is displayed in the output window, the XML fragment is a valid element:
     
    Completed validating xmlfragment
     
    NOTE: The XMLValidatingReader object validates only the type declarations and the top level elements in the XML Schema. XML fragments, such as sub elements, are considered to be local. You cannot pass XML fragments to XmlValidatingReader for direct validation unless you declare the XML fragments as top-level elements and set the reference at the required level.
     
    APPLIES TO
    - Microsoft Visual Basic .NET 2003 Standard Edition
    - Microsoft Visual Basic .NET 2002 Standard Edition
    - Microsoft .NET Framework 1.1
    - Microsoft .NET Framework 1.0

    Monday, May 7, 2007

    How to use XML

    - XML can keep data separated from your HTML

    - XML can be used to store data inside HTML documents

    - XML can be used as a format to exchange information

    - XML can be used to store data in files or in databases

    Source: XMLFiles

    How to serialize an object to XML by using Visual Basic .NET or Visual Basic 2005

    This step-by-step article describes how to serialize an object to XML by using Visual Basic .NET or Visual Basic 2005.

    This method is useful for persisting an object's state. This method is also useful for cloning an object by de-serializing the XML back to a new object.

    Source: Microsoft

    How to add style to XML

    The CSS2 Recommendation contains a brief tutorial on using CSS with XML.

    At the time CSS2 was written the official specification for style in XML wasn't ready. Here is what that tutorial should have contained. Note that the examples use CSS, but in most cases the style rules can also be written in XSL.

    Soure: Wc3