I Tried it, and wanted to know when and where i shop put the summary

zhaozj2021-02-16  67

Using the Windows Forms XML Parser Sample

By Joe Stegman

Download the Sample

Table of contents

Introduction

Basic Sample

Markup REFERENCE

Markup Parser Reference

Introduction

This is a sample of an extensible mechanism to add a markup model on top of an existing .NET Framework object model. This sample's parsing rules can be summarized as "XML elements map to .NET Framework types and XML attributes map to Type properties (or Events) ". This Sample Includes a Markup Parser That Dynamically Generates An Object Instance Tree from AN xi '

XML Namespace to .NET Framework Namespace Mapping

Object instancing

Object Identification and References

Property Sets

Instance and static method invocation

Event Wire-UPS

AskEMBLY REFERENCES

Disclaimer

THIS IS ISTER AGAINST The .NET Framework Version 1.1 And Has Not Been Tested Against The .NET Framework Version 1.1 And Has Not Been Tested Against Other Versions.

Basic Sample

.

XML Version = "1.0" encoding = "UTF-8"?>

Mapping XMLns = "http://www.microsoft.com/2003/windowsforms"

Namespace = "system.windows.forms; system.drawing"?>

XMLns: wfml = "http://www.microsoft.com/2003/wfml">

Form>

Wfml> The Windows Forms XML Parser Sample Will Generate An Instance Tree (form) from the Above XML. This Assumes The Above XML IS Contained IN A File named "sample.xml".

Markupparser Parser = New Markupparser ();

Object form = parser.parse ("Basic.xml");

This Will Dynamically Generate The Following Form:

Dissecting The Basic Sample

The Basic Sample Is Composed of An Xml Declaration, A Windows Forms Parser Specific Processing Instruction, a root tag, the instance declarations and an end tag. These sections area described Below:

XML Declaration

XML Version = "1.0" encoding = "UTF-8"?>

This is at the top of most xml files and is not specific to this sample.

Sample Processing Instruction

Mapping XMLns = "http://www.microsoft.com/2003/windowsforms"

Namespace = "system.windows.forms; system.drawing"?>

This line defines a mapping between an XML namespace and .NET Framework namespaces. This line declares that any elements defined in the XML namespace "http://www.microsoft.com/2003/WindowsForms" will map to types in the .NET Framework Namespaces "System.Windows.Forms or System.drawing". See The Markup Reference Section for More Information On The Mapping Processing Instruction.

Root tag

XMLns: wfml = "http://www.microsoft.com/2003/wfml">

This line defines the default XML namespace for the sample file ( "http://www.microsoft.com/2003/WindowsForms") and defines "wfml" as a prefix for elements and attributes in the "http://www.microsoft .COM / 2003 / WFML "Namespace.

Instance Declarations

Form>

When processing this XML, the parser will create an instance of type Form using the default Form constructor and set its Text property to "Basic Sample" and its Size property set to "300,200". The parser will create a "Label" and add it to the Form's Controls collection (see below for details) and set the Label's Text property to "Hello World", set the Label's AutoSize property to "True" and set the Label's Location property to "10,20". Finally, the parser will Call The Method "Show" on the form instance.

XML Namespace to .NET Framework Mappings

THE Sample Parser Creates An Instance of The System.Windows.Forms.form Type As a Result of Parsing The

转载请注明原文地址:https://www.9cbs.com/read-15341.html

New Post(0)