I am using edX Studio to make a course. I would like to make a custom python evaluated input problem. There seems to be an issue with the xml tags being closed by >
or <
symbols within the python code in the tag?
<?xml version="1.0"?>
<problem>
<p>Name as many online learning platforms as you can: </p>
<script type="loncapa/python">
def make_a_list(name_string):
return name_string.split(',')
def count_names(name_list):
return len(name_list)
def how_many_oli(expect, ans):
oli_names = ['udacity', 'udemy', 'codecademy', 'iktel'
'codeschool', 'khan academy', 'khanacademy', 'coursera', 'edx', 'iversity']
names = make_a_list(ans)
how_many = len(set(names))
message_hint = 'Good work!'
for e in names:
e=e.strip('"')
e=e.strip("'")
e=e.strip()
e=e.lower()
who_is = e
if e not in oli_names:
message_hint = message_hint+" Tell us about "+str(who_is).title()+"?"
if how_many < 1:
return { 'ok': False, 'msg': 'None at all?'}
if how_many < 5:
return { 'ok': True, 'msg': 'Only '+str(how_many)+"?"}
if how_many == 5:
return { 'ok': True, 'msg': message_hint }
if how_many > 5:
return { 'ok': True, 'msg': message_hint }
return False
</script>
<customresponse cfn="how_many_oli">
<textline size="100" />
</customresponse>
</problem>
How do I avoid this? I know I could change the code to avoid using <
and >
but there must be a way to use them or something similar?
Text content in XML ( character data ) must escape the <
, and &
characters using pre-defined XML entities . Python code is no exception:
if how_many < 1:
where <
is replaced with <
and &
with &
.
A proper XML parser will return text content un-escaped, replacing such entities with the original characters.
<
and >
are XML Entities. You'll need to escape them ie you'll need to use <
and >
instead. And if you use &
itself, &
.
If this is a pain, you can also put the whole thing in a CDATA section:
http://www.w3schools.com/xml/xml_cdata.asp
looks like this:
<script>
<![CDATA[
if how_many < 1:
return { 'ok': False, 'msg': 'None at all?'}
]]>
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.