小编kas*_*ten的帖子

如何通过DOM在xml文档中插入schemalocation

我用JAXP创建一个xml文档,并搜索插入schemalocation的方法.目前我的申请表:

<?xml version="1.0" encoding="UTF-8"?>
<root>
...
</root>
Run Code Online (Sandbox Code Playgroud)

但是我需要:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="namespaceURL" 
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="namespaceURL pathToMySchema.xsd">
...
</root>
Run Code Online (Sandbox Code Playgroud)

我的代码:

StreamResult result = new StreamResult(writer);
Document doc = getDocument();

Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.VERSION, "1.0");
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

DOMSource source = new DOMSource(depl.getAsElement(doc));
trans.transform(source, result);
Run Code Online (Sandbox Code Playgroud)

谢谢你的时间,
卡斯滕

xsd dom jaxp

6
推荐指数
2
解决办法
1万
查看次数

如何定义XML模式XPath的选择了递归式

编辑:添加键.

嗨,

我有一个xml架构,其中包含以下类型:

<xs:complexType name="definition">
  <xs:sequence/>
  <xs:attribute name="id"/>
</xs:complexType>

<xsd:key name="definitionId">
  <xsd:selector xpath="definition"/>
  <xsd:field xpath="@id"/>
</xsd:key>

<xs:complexType name="elem">
  <xs:sequence>
    <xs:element name="entry1" type="elem" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="entry2" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="ref" type="xs:string" use="required"/>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

这允许类似于:

<definition id="A">
<definition id="B">
<definition id="C">

<entry1 ref="A">
  <entry1 ref="B">
    <entry1 ref="C"/>
    <entry2/>
  </entry1>
  <entry1 ref="C">
  </entry1>
</entry1>
Run Code Online (Sandbox Code Playgroud)

我需要一个XPath选择器来声明ref属性的keyref,但我不知道如何定义递归路径.

<xsd:keyref name="definitionRef" refer="definitionId">
  <xsd:selector xpath="???"/>  <<<how to find all "ref" of entry1 ?    
  <xsd:field xpath="@ref"/>
</xsd:keyref>
Run Code Online (Sandbox Code Playgroud)

谢谢你的时间.

xml xsd

5
推荐指数
1
解决办法
2万
查看次数

在tkinter中生成点击事件

我正在尝试对我的 tkitner GUI 进行单元测试。

因此我尝试从单独的线程生成点击事件。下面是测试 Tkinter.Button 的示例:

import unittest, threading
from Tkinter import *

class clickThread(threading.Thread): 
    def __init__(self, root): 
        threading.Thread.__init__(self)
        self.root = root 

    def run(self): 
        button = filter(lambda a: isinstance(a, Button), self.root.children.values())[0]
        print button
        button.focus()
        button.event_generate("<Button-1>")
        button.event_generate("<ButtonRelease-1>")
        print "clicked"

class Test(unittest.TestCase):
    def testName(self):
        root = Tk()
        button = Button(root, command=self.returnEvent)
        button.pack()
        thread = clickThread(root)
        thread.start()
        root.mainloop()

    def returnEvent(self):
        print "!"
Run Code Online (Sandbox Code Playgroud)

我生成的单击事件未调用 Test.returnEvent 方法。但如果我真正点击一下,它就会按预期工作。

python unit-testing tkinter

2
推荐指数
1
解决办法
5194
查看次数

标签 统计

xsd ×2

dom ×1

jaxp ×1

python ×1

tkinter ×1

unit-testing ×1

xml ×1