10from xml.dom
import minidom
15 ns = namespace.getElementsByTagName(
"grammar")[0].getAttribute(
"ns")
16 return ooxUrlAliases[ns]
21 for k, v
in list(node.attributes.items()):
22 if k.startswith(
"xmlns:"):
23 ret[k.replace(
'xmlns:',
'')] = v
29 for i
in sock.readlines():
31 alias, url = line.split(
' ')[1:]
32 ooxUrlAliases[url] = alias
37 defines = [i.getAttribute(
"name")
for i
in model.getElementsByTagName(
"define")]
38 for reference
in [i.getAttribute(
"name")
for i
in model.getElementsByTagName(
"ref")]:
39 if reference
not in defines:
40 raise Exception(
"Unknown define element with name '%s'" % reference)
41 for start
in [i.getAttribute(
"name")
for i
in model.getElementsByTagName(
"start")]:
42 if start
not in defines:
43 raise Exception(
"Unknown start element with name '%s'" % start)
47 modelNode = [i
for i
in model.childNodes
if i.localName ==
"model"][0]
50 for i
in modelNode.getElementsByTagName(
"namespace"):
53 grammar = i.getElementsByTagName(
"grammar")[0]
55 for j
in i.getElementsByTagName(
"element") + i.getElementsByTagName(
"attribute"):
58 if ":" in j.getAttribute(
"name"):
59 nameprefix = j.getAttribute(
"name").split(
':')[0]
60 prefix = ooxUrlAliases[modelNamespaceAliases[nameprefix]]
61 elif j.localName ==
"attribute":
62 if grammar.getAttribute(
"attributeFormDefault") ==
"qualified":
63 prefix = grammarprefix
65 prefix = grammarprefix
68 if ":" in j.getAttribute(
"name"):
69 localname = j.getAttribute(
"name").split(
':')[1]
71 localname = j.getAttribute(
"name")
74 j.setAttribute(
"prefix", prefix)
75 j.setAttribute(
"localname", localname)
78namespacesPath = sys.argv[1]
79modelPath = sys.argv[2]
85model = minidom.parse(modelPath)
88model.writexml(sys.stdout)
def parseNamespaceAliases(node)
def prefixForGrammar(namespace)