---
title: "xml schema写法"
author: "major361"
date: "2008-03-18T18:01:46Z"
tags: []
slug: "xml-schema"
draft: false
lastmod: "2008-03-18T18:01:46Z"
id: 173482
url: "https://major361.iteye.com/blog/173482"
---

1.把xml文件和schema文件关联起来

1)和本地的shema关联

```xml
<rootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xsi:noNamespaceSchemaLocation="xxx.xsd">
或者xsi:noNamespaceSchemaLocation="file:///文件的路径">
```


2)第二种关联的方法
在xsd文件中定义如下：

```xml
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://localhost">
```


在xml文件中定义如下

```xml
<rootElement
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://localhost"
	xsi:schemaLocation="http://localhost planes.xsd">
<!--schemaLocation以命名空间开始然后接一个空格 再跟xsd文件名，可以多个-->
```


2.当elementFormDefault="unqualified" 表示全局元素和类型归于目标命名空间，而局部元素归于无名的命名空间
当elementFormDefault="qualified" 表示全局元素和类型，以及局部元素都归于目标命名空间

3.attributeFormDefault="qualified" 表示属性值归于目标命名空间
当attributeFormDefault="unqualified"时表示属性值归于拥有属性的元素？？对吗？？