File tree Expand file tree Collapse file tree 5 files changed +18
-10
lines changed
Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 99
1010from .compat import cls_method_fn
1111from .constants import RELATIONSHIP_TYPE as RT
12- from .oxml import CT_Relationships , nsmap , serialize_part_xml
12+ from .oxml import CT_Relationships , serialize_part_xml
1313from .packuri import PACKAGE_URI , PackURI
1414from .pkgreader import PackageReader
1515from .pkgwriter import PackageWriter
@@ -301,7 +301,7 @@ def _rel_ref_count(self, rId):
301301 identified by *rId*.
302302 """
303303 assert self ._element is not None
304- rIds = self ._element .xpath ('//@r:id' , namespaces = nsmap )
304+ rIds = self ._element .xpath ('//@r:id' )
305305 return len ([_rId for _rId in rIds if _rId == rId ])
306306
307307 # ----------------------------------------------------------------
Original file line number Diff line number Diff line change 66
77from .. import OxmlElement
88from ..shared import CT_DecimalNumber
9- from ..ns import nsmap , qn
9+ from ..ns import qn
1010from ..xmlchemy import BaseOxmlElement
1111
1212
@@ -181,7 +181,7 @@ def num_having_numId(self, numId):
181181 """
182182 xpath = './w:num[@w:numId="%d"]' % numId
183183 try :
184- return self .xpath (xpath , namespaces = nsmap )[0 ]
184+ return self .xpath (xpath )[0 ]
185185 except IndexError :
186186 raise KeyError ('no <w:num> element with numId %d' % numId )
187187
@@ -195,7 +195,7 @@ def _next_numId(self):
195195 1 and filling any gaps in numbering between existing ``<w:num>``
196196 elements.
197197 """
198- numId_strs = self .xpath ('./w:num/@w:numId' , namespaces = nsmap )
198+ numId_strs = self .xpath ('./w:num/@w:numId' )
199199 num_ids = [int (numId_str ) for numId_str in numId_strs ]
200200 for num in range (1 , len (num_ids )+ 2 ):
201201 if num not in num_ids :
Original file line number Diff line number Diff line change 44Custom element classes related to the styles part
55"""
66
7- from ..ns import nsmap , qn
7+ from ..ns import qn
88from ..xmlchemy import BaseOxmlElement
99
1010
@@ -29,7 +29,7 @@ def style_having_styleId(self, styleId):
2929 """
3030 xpath = './w:style[@w:styleId="%s"]' % styleId
3131 try :
32- return self .xpath (xpath , namespaces = nsmap )[0 ]
32+ return self .xpath (xpath )[0 ]
3333 except IndexError :
3434 raise KeyError ('no <w:style> element with styleId %d' % styleId )
3535
Original file line number Diff line number Diff line change 1111
1212import re
1313
14- from .ns import NamespacePrefixedTag , qn
14+ from .ns import NamespacePrefixedTag , nsmap , qn
1515from ..compat import Unicode
1616
1717
@@ -138,6 +138,15 @@ def xml(self):
138138 """
139139 return serialize_for_reading (self )
140140
141+ def xpath (self , xpath_str ):
142+ """
143+ Override of ``lxml`` _Element.xpath() method to provide standard Open
144+ XML namespace mapping (``nsmap``) in centralized location.
145+ """
146+ return super (BaseOxmlElement , self ).xpath (
147+ xpath_str , namespaces = nsmap
148+ )
149+
141150 @property
142151 def _nsptag (self ):
143152 return NamespacePrefixedTag .from_clark_name (self .tag )
Original file line number Diff line number Diff line change 1212from ..opc .oxml import serialize_part_xml
1313from ..opc .package import Part
1414from ..oxml import parse_xml
15- from ..oxml .ns import nsmap
1615from ..shape import InlineShape
1716from ..shared import lazyproperty , Parented
1817from ..table import Table
@@ -214,4 +213,4 @@ def add_picture(self, image_descriptor):
214213 def _inline_lst (self ):
215214 body = self ._body
216215 xpath = './w:p/w:r/w:drawing/wp:inline'
217- return body .xpath (xpath , namespaces = nsmap )
216+ return body .xpath (xpath )
You can’t perform that action at this time.
0 commit comments