2014-04-18 2 views
1

저는 pyxb에서 생성 된 XML에 스키마 위치를 추가 할 수있는 방법이 궁금합니다.PyXB 스키마 위치 추가

<ns1:myDocument xmlns:ns1="http://www.mydomain.com/path" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.mydomain.com/path myschema.xsd"> 

JAXB에서 내가

jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, 
     "http://www.mydomain.com/path myschema.xsd"); 

pyxb으로 그렇게하는 방법을 어떤 생각으로 그것을 달성 할 것?

많은 감사합니다.

답변

2

자동 지원은 없습니다. toDOM() 메소드를 사용한 다음 DOM 명령을 사용하여 속성을 문서에 추가 할 수 있습니다. 문서에서 이미 xsi 네임 스페이스를 사용하지 않으면 추가해야합니다.

import xml.dom.minidom 
from pyxb.namespace import XMLSchema_instance as xsi 
from pyxb.namespace import XMLNamespaces as xmlns 
v = instance.toDOM() 
v.documentElement.setAttributeNS(xsi.uri(), 'xsi:schemaLocation', 'urn:someurn') 
v.documentElement.setAttributeNS(xmlns.uri(), 'xmlns:xsi', xsi.uri()) 
print v.toxml('utf-8') 
관련 문제