World XML Schema Notes

1)
XML Support in Word 2003
XML support in Word 2003 is new exciting feature. Word 2003 now supports native XML vocabulary called Word Markup Language (WordML). Each document has the following basic structure:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument
    xmlns:w=http://schemas.microsoft.com/office/word/2003/wordml>
   <!-- WordML structure goes here -->
</w:wordDocument>
XML support in Word 2003 gives the end-user ability to add custom tags (and namespaces) to the document without corrupting its structure.


2)
Define data structure
(-----)
1. XML Data File
2. Generate the XSD file with the tool
In order to make Word generate XSD file for us - we will use Word Xml Toolbox, which should be downloaded from Microsoft site and installed.

Now we can try to open our XML file using word. We will see nothing special - just XML structure and data. Our goal is to create XSD file now and it can be achieved by clicking "Generate Inferred Schema" From XML Toolbox menu (see image below).


(-----)
or with Visual Studio XSD Editor//

XML Schema SimpleType vs ComplexType
Overview
An XML Schema is an XML-based representation of the structure of an XML document.
XML Schema supports data types and namespaces; a DTD does not.

A simpleType is represented with a <xs:simple Type/> declaration.

SimpleType with Restriction Element.
<xs:restriction base="xs:decimal">

Declaration <A>1.0</A> or <A>25.0</A> would not validate with the Schema.


ComplexType Declaration
A complexType is used to constrain elements and attributes in an XML document. It is represented with <xs:complex Type/>.


Simple Types versus Complex Types
Simple types and complex types differ in this way: simple types cannot have element children or attributes; complex types may have element children and attributes.

Tracing the type hierarchy down the branch of simple types, we see that the first simple type is anySimpleType, which is also type that you could actually use. W3C XML Schemas has 44 built-in simple types, each of which derives from anySimpleType, and all but three of which derive by restriction.
Not a single one derives by extension. To extend a simple type would mean to add element children or an attribute. This contradicts the definition of simple type in W3C Schemas and is thus prohibited.


3) Word XM Define with XSD

 

4) Coding

----1) define namespace manager

private static XmlNamespaceManager nsmgr =
new XmlNamespaceManager(new NameTable());


-----2)Opening XmlDocument is easy as well:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(XmlReader.Create(template));

----3)Next thing is to fill namespace manager with our namespaces:

nsmgr.AddNamespace("w",
"
http://schemas.microsoft.com/office/word/2003/wordml");
nsmgr.AddNamespace("ns0", "test-customer");


register two namespaces within manager

In this case WordML namespace should always have "w" prefix, while custom namespaces may vary.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值