Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:13:07+00:00 2026-06-10T09:13:07+00:00

My question revolves around a XML file I am working with it looks like

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:13:09+00:00Added an answer on June 10, 2026 at 9:13 am

    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:

    In [51]: import xml.dom.minidom as minidom
    
    In [52]: dom = minidom.parse("log.xml")
    
    In [53]: dom
    Out[53]: <xml.dom.minidom.Document instance at 0x97082ec>
    

    Now look inside the paths:

    In [55]: dom.getElementsByTagName("paths")
    Out[55]: [<DOM Element: paths at 0x97086cc>]
    
    In [56]: dom.getElementsByTagName("paths")[0]
    Out[56]: <DOM Element: paths at 0x97086cc>
    
    In [57]: vars(dom.getElementsByTagName("paths")[0])
    Out[57]: 
    {'_attrs': {},
     '_attrsNS': {},
     'childNodes': [<DOM Text node "u'\n\n'">,
      <DOM Element: path at 0x970874c>,
      <DOM Text node "u'   \n\n'">,
      <DOM Element: path at 0x97088ac>,
      <DOM Text node "u'\n\n'">],
     'namespaceURI': None,
     'nextSibling': <DOM Text node "u'\n'">,
     'nodeName': u'paths',
     'ownerDocument': <xml.dom.minidom.Document instance at 0x97082ec>,
     'parentNode': <DOM Element: logentry at 0x970848c>,
     'prefix': None,
     'previousSibling': <DOM Text node "u'\n'">,
     'tagName': u'paths'}
    

    Look at the childNodes:

    In [58]: dom.getElementsByTagName("paths")[0].childNodes
    Out[58]: 
    [<DOM Text node "u'\n\n'">,
     <DOM Element: path at 0x970874c>,
     <DOM Text node "u'   \n\n'">,
     <DOM Element: path at 0x97088ac>,
     <DOM Text node "u'\n\n'">]
    

    Whitespace is significant, so that’s a bit of a headache. Can throw the non-elements away, though:

    In [61]: elements = [x for x in dom.getElementsByTagName("paths")[0].childNodes if isinstance(x, minidom.Element)]
    
    In [62]: elements
    Out[62]: [<DOM Element: path at 0x970874c>, <DOM Element: path at 0x97088ac>]
    

    Looking inside:

    In [65]: elements
    Out[65]: [<DOM Element: path at 0x970874c>, <DOM Element: path at 0x97088ac>]
    
    In [66]: vars(elements[0])
    Out[66]: 
    {'_attrs': {u'action': <xml.dom.minidom.Attr instance at 0x970880c>,
      u'kind': <xml.dom.minidom.Attr instance at 0x97087ac>},
     '_attrsNS': {(None, u'action'): <xml.dom.minidom.Attr instance at 0x970880c>,
      (None, u'kind'): <xml.dom.minidom.Attr instance at 0x97087ac>},
     'childNodes': [<DOM Text node "u'/branches/'...">],
     'namespaceURI': None,
     'nextSibling': <DOM Text node "u'   \n\n'">,
     'nodeName': u'path',
     'ownerDocument': <xml.dom.minidom.Document instance at 0x97082ec>,
     'parentNode': <DOM Element: paths at 0x97086cc>,
     'prefix': None,
     'previousSibling': <DOM Text node "u'\n\n'">,
     'tagName': u'path'}
    

    And finally we know what we want:

    In [67]: for elem in elements:
        print elem, elem.childNodes[0].nodeValue, elem.getAttribute("kind"), elem.getAttribute("action") 
       ....:     
    <DOM Element: path at 0x970874c> /branches/Patch_4_2_0_Branch/text.xml file M
    <DOM Element: path at 0x97088ac> /branches/Patch_4_2_0_Branch dir M
    

    I can’t imagine not doing this interactively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question revolves around the use of curl_multi_exec in PHP. I am using code
I think my question revolves around me not having a comfortable grasp of page
My question revolves around CSS Fixed Layout vs a Float Layout that extends to
So my previous question revolved around turning wcf into a restful service convert a
Question I'd like the CSS background texture for my content area to begin immediately
Okay basically, I'm designing and developing a fairly complicated website which revolves around the
This might be a subjective question, but I'll give it a go. There are
Databinding in WPF/Silverlight revolves around dependency properties, DataContext objects and DataSource objects. As far
Sorry if this is a repeated question, I scanned the related questions and didn't
Note: This is a long winded question and requires a good understanding of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.