J
Jon Bowlas
HI all,
I'm fairly new to python and programming in general so I was hoping someone
here may be able to help me. Let me explain what the problem I'm having is:
I am trying to parse the XML of an attributes object I created, this object
has the structure outlined below. Everything is ok on the parsing front
until I try to get the values in ucl_navhide (StringField); these are
basically the id's of objects I wish to hide in a website navigation menu
separated by a space:
<uclattributes>
<ucl_title>root atts</ucl_title>
<ucl_banner_color>tb-black</ucl_banner_color>
<ucl_website_name>UCL Web Services</ucl_website_name>
<ucl_website_name_color>section_header_white</ucl_website_name_color>
<ucl_additional_name/>
<ucl_additional_name_color>section_subheader_white</ucl_additional_name_colo
r>
<ucl_logo>cms-assets/images/ucl0001</ucl_logo>
<ucl_breadcrumb_background_color>ucl0001</ucl_breadcrumb_background_color>
<ucl_menu>normal</ucl_menu>
<ucl_right_col_include>yes</ucl_right_col_include>
<ucl_columns>3_columns</ucl_columns>
<ucl_navhide>test1 test2</ucl_navhide>
</uclattributes>
I have a script 'normalmenu' that I will eventually be using to generate a
navigation menu for a website here it is in its present development state:
attobject = context.get_attobject()
navstring = context.get_uclattribute(attobject, 'ucl_navhide')
hiddennavelements = navstring.split(' ')
for hiddennavelement in hiddennavelements:
return hiddennavelement
So the script 'get_attobject' basically looks for an instance of the
attributes object in the current folder, if it doesn't locate one then it
uses acquisition to find one in a parent folder. The script
'get_uclattribute' then gets the nodeValues of the requested node. In this
instance its ucl_navhide, then I split the 'navstring' string at the spaces
and attempt the for-loop to output each of the values.
Unfortunately it appears I am unable to loop through each of the list items
in hiddennavelements, as it only returns the first value & will not repeat.
Strangely if I test to output the value of hiddennavelements it looks like
this: [u'test1', u'test2'] which I believe the u refers to Unicode, although
I could be wrong. Even more bizarrely if I test the len(hiddennavelements)
it returns the correct result (2), so why wont my for-loop work?
Hope someone can help, or point out my schoolboy error.
Jon
I'm fairly new to python and programming in general so I was hoping someone
here may be able to help me. Let me explain what the problem I'm having is:
I am trying to parse the XML of an attributes object I created, this object
has the structure outlined below. Everything is ok on the parsing front
until I try to get the values in ucl_navhide (StringField); these are
basically the id's of objects I wish to hide in a website navigation menu
separated by a space:
<uclattributes>
<ucl_title>root atts</ucl_title>
<ucl_banner_color>tb-black</ucl_banner_color>
<ucl_website_name>UCL Web Services</ucl_website_name>
<ucl_website_name_color>section_header_white</ucl_website_name_color>
<ucl_additional_name/>
<ucl_additional_name_color>section_subheader_white</ucl_additional_name_colo
r>
<ucl_logo>cms-assets/images/ucl0001</ucl_logo>
<ucl_breadcrumb_background_color>ucl0001</ucl_breadcrumb_background_color>
<ucl_menu>normal</ucl_menu>
<ucl_right_col_include>yes</ucl_right_col_include>
<ucl_columns>3_columns</ucl_columns>
<ucl_navhide>test1 test2</ucl_navhide>
</uclattributes>
I have a script 'normalmenu' that I will eventually be using to generate a
navigation menu for a website here it is in its present development state:
attobject = context.get_attobject()
navstring = context.get_uclattribute(attobject, 'ucl_navhide')
hiddennavelements = navstring.split(' ')
for hiddennavelement in hiddennavelements:
return hiddennavelement
So the script 'get_attobject' basically looks for an instance of the
attributes object in the current folder, if it doesn't locate one then it
uses acquisition to find one in a parent folder. The script
'get_uclattribute' then gets the nodeValues of the requested node. In this
instance its ucl_navhide, then I split the 'navstring' string at the spaces
and attempt the for-loop to output each of the values.
Unfortunately it appears I am unable to loop through each of the list items
in hiddennavelements, as it only returns the first value & will not repeat.
Strangely if I test to output the value of hiddennavelements it looks like
this: [u'test1', u'test2'] which I believe the u refers to Unicode, although
I could be wrong. Even more bizarrely if I test the len(hiddennavelements)
it returns the correct result (2), so why wont my for-loop work?
Hope someone can help, or point out my schoolboy error.
Jon