My question revolves around a XML file I am working with it looks like this.
<log>
<logentry
revision="33185">
<author>glv</author>
<date>2012-08-06T21:01:52.494219Z</date>
<paths>
<path
kind="file"
action="M">/branches/Patch_4_2_0_Branch/text.xml</path>
<path
kind="dir"
action="M">/branches/Patch_4_2_0_Branch</path>
</paths>
<msg>PATCH_BRANCH:N/A
BUG_NUMBER:N/A
FEATURE_AFFECTED:N/A
OVERVIEW:N/A
Adding the SVN log size requirement to the branch
</msg>
</logentry>
</log>
Now what I want to do is I want to use a “if” statement on this to look in the xml path tag to check if it is a kind= dir or a kind = file. and then add the path to a varible called content. This is what I have so far for it. I am using dom.import btw.
xmlPath = dom.getElementsByTagName('paths')[0]
xmlPathM = xmlPath.getAttribute('kind')
if xmlPathM == dir:
content += "Directory location:" + xmlPathM +"\n \n"
else:
content += "FileName" + xmlPathM +"\n \n "
Now it doesn’t seem to want to work it will print out FileName in it but not the Directory location. I believe but i want it to look at this logentry and print out this
Directory location: /branches/Patch_4_2_0_Branch
FileName:/branches/Patch_4_2_0_Branch/text.xml
for the same log-entry.
Any idea as to what I am missing or doing wrong?
Working with XML is a great thing to do with a good interactive console, like IPython. [Side note: I prefer ElementTree because I like the interface more, but whatever]
Let’s dive in. First read it in:
Now look inside the paths:
Look at the
childNodes:Whitespace is significant, so that’s a bit of a headache. Can throw the non-elements away, though:
Looking inside:
And finally we know what we want:
I can’t imagine not doing this interactively.