forked from openlp/openlp
Start customisation
This commit is contained in:
parent
0f53c65f4f
commit
9910655223
@ -57,15 +57,15 @@ class CustomXMLBuilder(object):
|
||||
Set up the song builder.
|
||||
"""
|
||||
# Create the minidom document
|
||||
self.song_xml = Document()
|
||||
self.custom_xml = Document()
|
||||
|
||||
def new_document(self):
|
||||
"""
|
||||
Create a new song XML document.
|
||||
"""
|
||||
# Create the <song> base element
|
||||
self.song = self.song_xml.createElement(u'song')
|
||||
self.song_xml.appendChild(self.song)
|
||||
self.song = self.custom_xml.createElement(u'song')
|
||||
self.custom_xml.appendChild(self.song)
|
||||
self.song.setAttribute(u'version', u'1.0')
|
||||
|
||||
def add_lyrics_to_song(self):
|
||||
@ -74,7 +74,7 @@ class CustomXMLBuilder(object):
|
||||
song.
|
||||
"""
|
||||
# Create the main <lyrics> element
|
||||
self.lyrics = self.song_xml.createElement(u'lyrics')
|
||||
self.lyrics = self.custom_xml.createElement(u'lyrics')
|
||||
self.lyrics.setAttribute(u'language', u'en')
|
||||
self.song.appendChild(self.lyrics)
|
||||
|
||||
@ -93,25 +93,25 @@ class CustomXMLBuilder(object):
|
||||
The actual text of the verse to be stored.
|
||||
"""
|
||||
#log.debug(u'add_verse_to_lyrics %s, %s\n%s' % (type, number, content))
|
||||
verse = self.song_xml.createElement(u'verse')
|
||||
verse = self.custom_xml.createElement(u'verse')
|
||||
verse.setAttribute(u'type', type)
|
||||
verse.setAttribute(u'label', number)
|
||||
self.lyrics.appendChild(verse)
|
||||
# add data as a CDATA section to protect the XML from special chars
|
||||
cds = self.song_xml.createCDATASection(content)
|
||||
cds = self.custom_xml.createCDATASection(content)
|
||||
verse.appendChild(cds)
|
||||
|
||||
def dump_xml(self):
|
||||
"""
|
||||
Debugging aid to dump XML so that we can see what we have.
|
||||
"""
|
||||
return self.song_xml.toprettyxml(indent=u' ')
|
||||
return self.custom_xml.toprettyxml(indent=u' ')
|
||||
|
||||
def extract_xml(self):
|
||||
"""
|
||||
Extract our newly created XML song.
|
||||
"""
|
||||
return self.song_xml.toxml(u'utf-8')
|
||||
return self.custom_xml.toxml(u'utf-8')
|
||||
|
||||
|
||||
class CustomXMLParser(object):
|
||||
@ -127,9 +127,9 @@ class CustomXMLParser(object):
|
||||
``xml``
|
||||
The XML of the song to be parsed.
|
||||
"""
|
||||
self.song_xml = None
|
||||
self.custom_xml = None
|
||||
try:
|
||||
self.song_xml = ElementTree(
|
||||
self.custom_xml = ElementTree(
|
||||
element=XML(unicode(xml).encode('unicode-escape')))
|
||||
except ExpatError:
|
||||
log.exception(u'Invalid xml %s', xml)
|
||||
@ -139,7 +139,7 @@ class CustomXMLParser(object):
|
||||
Iterates through the verses in the XML and returns a list of verses
|
||||
and their attributes.
|
||||
"""
|
||||
xml_iter = self.song_xml.getiterator()
|
||||
xml_iter = self.custom_xml.getiterator()
|
||||
verse_list = []
|
||||
for element in xml_iter:
|
||||
if element.tag == u'verse':
|
||||
@ -153,4 +153,4 @@ class CustomXMLParser(object):
|
||||
"""
|
||||
Debugging aid to dump XML so that we can see what we have.
|
||||
"""
|
||||
return dump(self.song_xml)
|
||||
return dump(self.custom_xml)
|
||||
|
Loading…
Reference in New Issue
Block a user