复杂元素的两个例子

例1:
Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="book_info" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="book_info">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="author" maxOccurs="3">
<xs:simpleType>
<xs:list itemType="author_3"/>
</xs:simpleType>
</xs:element>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:complexType>
<xs:simpleType name="author_3">
<xs:restriction base="xs:string">
<xs:enumeration value="张三"/>
<xs:enumeration value="李四"/>
<xs:enumeration value="赵五"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

XML文档:
<?xml version="1.0"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="019.xsd">
<book id="001">
<name>XML学习天下</name>
<author>张三</author>
<author>李四</author>
<price>88.50</price>
</book>
<book id="002">
<name>XML百例</name>
<author>赵五</author>
<author>李四</author>
<price>68.00</price>
</book>
</books>
注:书的作者只能是张三、李四和赵五。

例2:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded" type="book_value"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="book_value">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="author" type="author_3" maxOccurs="3"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:complexType>
<xs:simpleType name="author_3">
<xs:restriction base="xs:string">
<xs:enumeration value="张三"/>
<xs:enumeration value="李四"/>
<xs:enumeration value="赵五"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

XML文档:
<?xml version="1.0"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="018.xsd">
<book id="001">
<name>XML学习天下</name>
<author>张三</author>
<price>88.50</price>
</book>
<book id="002">
<name>XML百例</name>
<author>赵五</author>
<price>68.00</price>
</book>
</books>
注:书的作者只能是张三、李四、赵五其中的一个。
Vue 中实现两个元素拖动并互相影响位置,通常会涉及到拖拽库如 Vue-Draggable 或者 Vanilla JavaScript 的 drag&drop API,以及一些计算和事件处理技术。以下是一个简单的步骤说明: 1. **安装库**:首先安装相应的拖拽库,例如 `vue-draggable`,通过 npm 安装: ``` npm install vue-draggable ``` 2. **组件绑定**:在需要拖拽的 Vue 组件中,使用 `v-draggable` 或者自定义的 draggable 函数,并设置 `bind` 和 `update` 事件监听器来跟踪元素的位置变化。 ```html <template> <div v-for="(item, index) in items" :key="index"> <draggable :model="item" :move="handleDrag"> <span>{{ item.name }}</span> </draggable> </div> </template> <script> import draggable from 'vue-draggable'; export default { components: { draggable }, data() { return { items: [ { name: 'Element 1', position: { x: 0, y: 0 } }, { name: 'Element 2', position: { x: 50, y: 50 } } ] }; }, methods: { handleDrag({ model, el, event }) { // 当元素被移动时,更新模型和相应元素的位置 model.position = { x: event.pageX - el.offsetLeft, y: event.pageY - el.offsetTop }; // 如果你想让这两个元素相互影响位置,可以在这里添加计算逻辑 if (model === this.items[1]) { this.items[0].position.x += model.position.x; this.items[0].position.y += model.position.y; } } } }; </script> ``` 在这个例子中,当第一个元素被拖动时,它的位置会影响第二个元素的位置。如果你想要更复杂的交互,比如限制元素之间的距离、碰撞检测等,可能需要进一步定制逻辑或引入第三方库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值