How do I crawl through this directory... User_Profile and use a for loop to pull these 3 elements ou
"Jaared Scott" <[email protected]> Thu, 08 Jan 2004 15:42:15 -0600
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <[email protected]> |
--===============0309053318==
Content-Type: multipart/alternative; boundary="=_B3ED7CD7.59384386"
--=_B3ED7CD7.59384386
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
How do I crawl through this directory... User_Profile and use a for loop =
to pull these 3 elements out of each of these users xml file? I can pull =
the info on one of them but I am a newbie to python and do not know how to =
do this in a Zope environment.... I have the py script below and thus far =
can pull what I need for the Authenticated user only...
=20
- User_Profile (this is a folder)
-user1.xml (these are parsedXML files)
-user2.xml
-user3.xml(sample elements for user3.xml)
<name>jim smith</name>
<campus>widgets campus</campus>
<duty>a</duty>
=20
Here is what I have coded... with the output (return peer) =3D [['jim =
smith',' widgets campus', 'a']]
=20
=20
# Example code:
=20
# Import a standard function, and get the HTML request and response =
objects.
from Products.PythonScripts.standard import html_quote
request =3D container.REQUEST
RESPONSE =3D request.RESPONSE
=20
# Example code:
=20
# Import a standard function, and get the HTML request and response =
objects.
from Products.PythonScripts.standard import html_quote
request =3D container.REQUEST
RESPONSE =3D request.RESPONSE
=20
# Return a string identifying this script.
=20
username =3D request.AUTHENTICATED_USER.getUserName()
profilefolder =3D context.user_profiles
peer =3D []
sub =3D []
=20
doc =3D profilefolder[username].getDOM()
all =3D profilefolder.objectValues()
=20
=20
=20
for id in doc.documentElement.getElementsByTagName("name")[0].getElementsBy=
TagName("id"):
name_item =3D id.firstChild.nodeValue
sub.append(name_item)
=20
for campus in doc.documentElement.getElementsByTagName("campuses")[0].g=
etElementsByTagName("campus"):
campus_item =3D campus.firstChild.nodeValue
sub.append(campus_item)
=20
for duty in doc.documentElement.getElementsByTagName("goal_writing")=
[0].getElementsByTagName("duty"):
duty_text =3D duty.firstChild.nodeValue
sub.append(duty_text)
peer.append(sub) =20
=20
return peer
=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=20
Jaared Scott
Application Developer
Oklahoma Department of Career and Technology Education
405 743 5176
[email protected]
--=_B3ED7CD7.59384386
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Description: HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1"=
>
<META content=3D"MSHTML 6.00.2800.1264" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN-TOP: 2px; FONT: 8pt Tahoma; MARGIN-LEFT: 2px">
<DIV><FONT size=3D2>How do I crawl through this directory... User_Prof=
ile and=20
use a for loop to pull these 3 elements out of each of these users xml=20
file? I can pull the info on one of them but I am a newbie to python =
and=20
do not know how to do this in a Zope environment.... I have the py =
script=20
below and thus far can pull what I need for the Authenticated user=20
only...</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2> - User_Profile (this is a folder)</FONT></DIV>
<DIV><FONT size=3D2> -user1.xml (these are parsedXML=20
files)</FONT></DIV>
<DIV><FONT size=3D2> -user2.xml</FONT></DIV>
<DIV><FONT size=3D2> -user3.xml(sample elements =
for=20
user3.xml)</FONT></DIV>
<DIV><FONT=20
size=3D2> =
=20
<name>jim smith</name></FONT></DIV>
<DIV><FONT=20
size=3D2> =
=20
<campus>widgets campus</campus></FONT></DIV>
<DIV><FONT=20
size=3D2> =
=20
<duty>a</duty></FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Here is what I have coded... with the output (return=20=
peer) =3D [['jim smith',' widgets campus', 'a']]</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV># Example code:</DIV>
<DIV> </DIV>
<DIV># Import a standard function, and get the HTML request and response=20=
objects.<BR>from Products.PythonScripts.standard import html_quote<BR>reque=
st =3D=20
container.REQUEST<BR>RESPONSE =3D request.RESPONSE</DIV>
<DIV> </DIV>
<DIV><BR># Example code:</DIV>
<DIV> </DIV>
<DIV># Import a standard function, and get the HTML request and response=20=
objects.<BR>from Products.PythonScripts.standard import html_quote<BR>reque=
st =3D=20
container.REQUEST<BR>RESPONSE =3D request.RESPONSE</DIV>
<DIV> </DIV>
<DIV># Return a string identifying this script.</DIV>
<DIV> </DIV>
<DIV><BR>username =3D request.AUTHENTICATED_USER.getUserName()<BR>profilefo=
lder =3D=20
context.user_profiles<BR>peer =3D []<BR>sub =3D []</DIV>
<DIV> </DIV>
<DIV>doc =3D profilefolder[username].getDOM()<BR>all =3D=20
profilefolder.objectValues()</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>for id in=20
doc.documentElement.getElementsByTagName("name")[0].getElementsByTagName("i=
d"):<BR> =20
name_item =3D id.firstChild.nodeValue<BR> =20
sub.append(name_item)</DIV>
<DIV> </DIV>
<DIV> for campus in=20
doc.documentElement.getElementsByTagName("campuses")[0].getElementsByTagNam=
e("campus"):<BR> =20
campus_item =3D=20
campus.firstChild.nodeValue<BR> =20
sub.append(campus_item)<BR> =
=20
<BR> for duty in=20
doc.documentElement.getElementsByTagName("goal_writing")[0].getElementsByTa=
gName("duty"):<BR> &nb=
sp; =20
duty_text =3D=20
duty.firstChild.nodeValue<BR> &nbs=
p; =20
sub.append(duty_text)<BR> &n=
bsp; =20
peer.append(sub) </DIV>
<DIV> </DIV>
<DIV>return peer<BR></DIV>
<DIV> </DIV>
<DIV>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</D=
IV>
<DIV> </DIV>
<DIV>Jaared Scott<BR>Application Developer<BR>Oklahoma Department of =
Career and=20
Technology Education<BR>405 743 5176<BR><A=20
href=3D"mailto:[email protected]">[email protected]</A></DIV></BO=
DY></HTML>
--=_B3ED7CD7.59384386--
--===============0309053318==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Parsed-XML-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/parsed-xml-dev
--===============0309053318==--