forked from openlp/openlp
Fixed Tim Bentley's problem with the loading sequence of modules.
Changed some names and quotes in xml1.py. bzr-revno: 415
This commit is contained in:
parent
b525734702
commit
eaa1aa81fd
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
||||
<!-- eric4 user project file for project openlp.org 2.0 -->
|
||||
<!-- Saved: 2009-03-10, 19:41:39 -->
|
||||
<!-- Saved: 2009-03-13, 00:02:12 -->
|
||||
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||
<UserProject version="4.0">
|
||||
</UserProject>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
|
||||
<!-- eric4 tasks file for project openlp.org 2.0 -->
|
||||
<!-- Saved: 2009-03-10, 19:41:39 -->
|
||||
<!-- Saved: 2009-03-13, 00:02:14 -->
|
||||
<Tasks version="4.2">
|
||||
<Task priority="1" completed="False" bugfix="False">
|
||||
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-4.6.dtd">
|
||||
<!-- eric4 project file for project openlp.org 2.0 -->
|
||||
<!-- Saved: 2009-03-09, 22:34:51 -->
|
||||
<!-- Saved: 2009-03-11, 21:25:53 -->
|
||||
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||
<Project version="4.6">
|
||||
<Language>en</Language>
|
||||
@ -152,11 +152,7 @@
|
||||
<Source>openlp/plugins/custom/lib/manager.py</Source>
|
||||
<Source>openlp/plugins/images/lib/mediaitem.py</Source>
|
||||
<Source>openlp/plugins/songs/lib/mediaitem.py</Source>
|
||||
<Source>resources/forms/Ui_editsongdialog.py</Source>
|
||||
<Source>resources/forms/Ui_editversedialog.py</Source>
|
||||
<Source>resources/forms/Ui_settings.py</Source>
|
||||
<Source>resources/forms/Ui_authorsdialog.py</Source>
|
||||
<Source>resources/forms/Ui_songbookdialog.py</Source>
|
||||
<Source>xml1.py</Source>
|
||||
</Sources>
|
||||
<Forms>
|
||||
<Form>resources/forms/openlpexportform.ui</Form>
|
||||
|
@ -18,10 +18,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
from textlistdata import TextListData
|
||||
from manager import CustomManager
|
||||
from customtab import CustomTab
|
||||
from mediaitem import CustomMediaItem
|
||||
from textlistdata import TextListData
|
||||
|
||||
__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'TextListData']
|
||||
|
||||
|
53
xml1.py
53
xml1.py
@ -1,4 +1,4 @@
|
||||
from xml.dom.minidom import Document
|
||||
from xml.dom.minidom import Document
|
||||
from xml.etree.ElementTree import ElementTree, XML, dump
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -13,67 +13,67 @@ from xml.etree.ElementTree import ElementTree, XML, dump
|
||||
"""
|
||||
class SongXMLBuilder():
|
||||
def __init__(self):
|
||||
# Create the minidom document
|
||||
# Create the minidom document
|
||||
self.song_xml = Document()
|
||||
|
||||
|
||||
def new_document(self):
|
||||
# Create the <song> base element
|
||||
self.song = self.song_xml.createElement("song")
|
||||
self.song = self.song_xml.createElement(u'song')
|
||||
self.song_xml.appendChild(self.song)
|
||||
self.song.setAttribute("version", "1.0")
|
||||
|
||||
self.song.setAttribute(u'version', u'1.0')
|
||||
|
||||
def add_lyrics_to_song(self):
|
||||
# Create the main <lyrics> element
|
||||
self.lyrics = self.song_xml.createElement("lyrics")
|
||||
self.lyrics.setAttribute("language", "en")
|
||||
self.lyrics = self.song_xml.createElement(u'lyrics')
|
||||
self.lyrics.setAttribute(u'language', u'en')
|
||||
self.song.appendChild(self.lyrics)
|
||||
|
||||
def add_verse_to_lyrics(self, type, number, content):
|
||||
|
||||
def add_verse_to_lyrics(self, type, label, content):
|
||||
"""
|
||||
type - type of verse (Chorus, Verse , Bridge, Custom etc
|
||||
number - number of item eg verse 1
|
||||
label - label of item eg verse 1
|
||||
content - the text to be stored
|
||||
"""
|
||||
verse = self.song_xml.createElement("verse")
|
||||
verse.setAttribute("type", type)
|
||||
verse.setAttribute('label', number)
|
||||
verse = self.song_xml.createElement(u'verse')
|
||||
verse.setAttribute(u'type', type)
|
||||
verse.setAttribute(u'label', label)
|
||||
self.lyrics.appendChild(verse)
|
||||
|
||||
|
||||
# add data as a CDATA section
|
||||
cds = self.song_xml.createCDATASection(content)
|
||||
verse.appendChild(cds)
|
||||
|
||||
|
||||
def dump_xml(self):
|
||||
# Debugging aid to see what we have
|
||||
print self.song_xml.toprettyxml(indent=" ")
|
||||
|
||||
print self.song_xml.toprettyxml(indent=u' ')
|
||||
|
||||
def extract_xml(self):
|
||||
# Print our newly created XML
|
||||
return self.song_xml.toxml()
|
||||
|
||||
|
||||
class SongXMLParser():
|
||||
def __init__(self, xml):
|
||||
self.song_xml = ElementTree(element=XML(xml))
|
||||
|
||||
|
||||
def get_verses(self):
|
||||
#return a list of verse's and attributes
|
||||
iter=self.song_xml.getiterator()
|
||||
verse_list = []
|
||||
for element in iter:
|
||||
if element.tag == 'verse':
|
||||
for element in iter:
|
||||
if element.tag == u'verse':
|
||||
verse_list.append([element.attrib, element.text])
|
||||
return verse_list
|
||||
|
||||
|
||||
def dump_xml(self):
|
||||
# Debugging aid to see what we have
|
||||
print dump(self.song_xml)
|
||||
|
||||
if __name__=="__main__":
|
||||
if __name__ == '__main__':
|
||||
sxml=SongXMLBuilder()
|
||||
sxml.new_document()
|
||||
sxml.add_lyrics_to_song()
|
||||
sxml.add_verse_to_lyrics(u'chorus', u'1', u'The is\n is \nsome\n text')
|
||||
sxml.add_verse_to_lyrics(u'verse', u'2', u'The is\n is \nmore\n text')
|
||||
sxml.add_verse_to_lyrics(u'verse', u'2', u'The is\n is \nmore\n text')
|
||||
sxml.dump_xml()
|
||||
x1 = sxml.extract_xml()
|
||||
print x1
|
||||
@ -81,6 +81,3 @@ if __name__=="__main__":
|
||||
spra=SongXMLParser(x1)
|
||||
vl = spra.get_verses()
|
||||
print vl
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user