[Libreoffice-commits] core.git: writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Sep 3 13:39:35 PDT 2014
writerfilter/source/ooxml/model.xml | 12 ++++++++----
writerfilter/source/ooxml/modelpreprocess.py | 18 ++++++------------
2 files changed, 14 insertions(+), 16 deletions(-)
New commits:
commit 5b7920eec325620cf0b511980874551449e00ad9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Sep 3 22:22:51 2014 +0200
Require all namespace aliases to be defined on the root element
Change-Id: I8aa53f4aacd86a331b42a9bb3575015e6857c07b
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index cc826d5..4790dbe 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -21,13 +21,17 @@
xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"
xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"
+ xmlns:o="urn:schemas-microsoft-com:office:office"
+ xmlns:p="urn:schemas-microsoft-com:office:powerpoint"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
- xmlns:rng="http://relaxng.org/ns/structure/1.0"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
+ xmlns:wvml="urn:schemas-microsoft-com:office:word"
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<token tokenid="ooxml:shape"/>
<token tokenid="ooxml:token"/>
@@ -7186,7 +7190,7 @@
<namespace name="shared-math" file="shared-math.rng">
<start name="oMathPara"/>
<start name="oMath"/>
- <grammar xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns="http://relaxng.org/ns/structure/1.0" ns="http://schemas.openxmlformats.org/officeDocument/2006/math" attributeFormDefault="qualified">
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="http://schemas.openxmlformats.org/officeDocument/2006/math" attributeFormDefault="qualified">
<!-- ISO RELAX NG Schema -->
<include href="wml.rng"/>
<!-- start = mathPr | oMathPara | oMath -->
@@ -8459,7 +8463,7 @@
<start name="polyline"/>
<start name="rect"/>
<start name="roundrect"/>
- <grammar xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wvml="urn:schemas-microsoft-com:office:word" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://relaxng.org/ns/structure/1.0" ns="urn:schemas-microsoft-com:vml">
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="urn:schemas-microsoft-com:vml">
<!-- ISO RELAX NG Schema -->
<include href="vml-officeDrawing.rng"/>
<!-- External schema: http://schemas.openxmlformats.org/wordprocessingml/2006/main -->
@@ -10612,7 +10616,7 @@
<start name="styles"/>
<start name="document"/>
<start name="glossaryDocument"/>
- <grammar xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:rel="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns="http://relaxng.org/ns/structure/1.0" ns="http://schemas.openxmlformats.org/wordprocessingml/2006/main" attributeFormDefault="qualified">
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="http://schemas.openxmlformats.org/wordprocessingml/2006/main" attributeFormDefault="qualified">
<include href="shared-math.rng"/>
<include href="dml-wordprocessingDrawing.rng"/>
<include href="shared-relationshipReference.rng"/>
diff --git a/writerfilter/source/ooxml/modelpreprocess.py b/writerfilter/source/ooxml/modelpreprocess.py
index 4874f30..2367e5c 100644
--- a/writerfilter/source/ooxml/modelpreprocess.py
+++ b/writerfilter/source/ooxml/modelpreprocess.py
@@ -31,10 +31,12 @@ def prefixForGrammar(namespace):
return prefixFromUrl(ns)
-def parseNamespaceAliases(node, ret):
+def parseNamespaceAliases(node):
+ ret = {}
for k, v in list(node.attributes.items()):
if k.startswith("xmlns:"):
ret[k.replace('xmlns:', '')] = v
+ return ret
def parseNamespaces(fro):
@@ -60,30 +62,22 @@ def check(model):
def preprocess(model):
modelNode = [i for i in model.childNodes if i.localName == "model"][0]
+ # Alias -> URL, based on "xmlns:" attributes.
+ modelNamespaceAliases = parseNamespaceAliases(modelNode)
for i in modelNode.getElementsByTagName("namespace"):
grammarprefix = prefixForGrammar(i)
- grammarNamespaceAliases = {}
- parseNamespaceAliases(modelNode, grammarNamespaceAliases)
grammar = i.getElementsByTagName("grammar")[0]
- parseNamespaceAliases(grammar, grammarNamespaceAliases)
-
for j in i.getElementsByTagName("element") + i.getElementsByTagName("attribute"):
if j.localName == "attribute" and not len(j.getAttribute("name")):
continue
- localNamespaceAliases = grammarNamespaceAliases.copy()
-
- parseNamespaceAliases(j.parentNode, localNamespaceAliases)
- parseNamespaceAliases(j, localNamespaceAliases)
-
# prefix
prefix = ""
if ":" in j.getAttribute("name"):
nameprefix = j.getAttribute("name").split(':')[0]
- if nameprefix in list(localNamespaceAliases.keys()):
- prefix = prefixFromUrl(localNamespaceAliases[nameprefix])
+ prefix = prefixFromUrl(modelNamespaceAliases[nameprefix])
elif j.localName == "attribute":
if grammar.getAttribute("attributeFormDefault") == "qualified":
prefix = grammarprefix
More information about the Libreoffice-commits
mailing list