Skip to content

Commit d49c0f5

Browse files
author
Steve Canny
committed
oxml: convert CT_String to xmlchemy
1 parent e77bbdd commit d49c0f5

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

docx/oxml/shared.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from . import OxmlElement
1010
from .ns import qn
11-
from .simpletypes import ST_DecimalNumber, ST_OnOff
11+
from .simpletypes import ST_DecimalNumber, ST_OnOff, ST_String
1212
from .xmlchemy import BaseOxmlElement, OptionalAttribute, RequiredAttribute
1313

1414

@@ -42,34 +42,34 @@ class CT_String(BaseOxmlElement):
4242
Used for ``<w:pStyle>`` and ``<w:tblStyle>`` elements and others,
4343
containing a style name in its ``val`` attribute.
4444
"""
45+
val = RequiredAttribute('w:val', ST_String)
46+
4547
@classmethod
4648
def new(cls, nsptagname, val):
4749
"""
4850
Return a new ``CT_String`` element with tagname *nsptagname* and
4951
``val`` attribute set to *val*.
5052
"""
51-
return OxmlElement(nsptagname, attrs={qn('w:val'): val})
53+
elm = OxmlElement(nsptagname)
54+
elm.val = val
55+
return elm
5256

5357
@classmethod
5458
def new_pStyle(cls, val):
5559
"""
5660
Return a new ``<w:pStyle>`` element with ``val`` attribute set to
5761
*val*.
5862
"""
59-
return OxmlElement('w:pStyle', attrs={qn('w:val'): val})
63+
pStyle = OxmlElement('w:pStyle')
64+
pStyle.val = val
65+
return pStyle
6066

6167
@classmethod
6268
def new_rStyle(cls, val):
6369
"""
6470
Return a new ``<w:rStyle>`` element with ``val`` attribute set to
6571
*val*.
6672
"""
67-
return OxmlElement('w:rStyle', attrs={qn('w:val'): val})
68-
69-
@property
70-
def val(self):
71-
return self.get(qn('w:val'))
72-
73-
@val.setter
74-
def val(self, val):
75-
return self.set(qn('w:val'), val)
73+
rStyle = OxmlElement('w:rStyle')
74+
rStyle.val = val
75+
return rStyle

docx/oxml/simpletypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ class ST_RelationshipId(XsdString):
199199
pass
200200

201201

202+
class ST_String(XsdString):
203+
pass
204+
205+
202206
class ST_UniversalMeasure(BaseSimpleType):
203207

204208
@classmethod

0 commit comments

Comments
 (0)