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

  • SEARCH
  • Home
  • 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 7624317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:55:52+00:00 2026-05-31T04:55:52+00:00

I am trying to solve a problem /implementation using xpath. Using code (python) is

  • 0

I am trying to solve a problem/implementation using xpath. Using code (python) is of course also possible, but I prefer to do it in xpath if possible

Right, say I’ve got a xml file that looks a bit like this:

<?xml version="1.0" encoding="UTF-8"?>
<dir>
    <results>
        <entrylist>
            <entry>
                <type>document</type>
                <name>a file name 1</name>
                <date>2012-01-01</date>
                <size>65421316516</size>
            </entry>
            <entry>
                <type>document</type>
                <name>a file name 2</name>
                <date>2012-01-02</date>
                <size>6542131</size>
            </entry>
            <entry>
                <type>document</type>
                <name>a file name 3</name>
                <date>2012-01-03</date>
                <size>654</size>
            </entry>
        </entrylist>
    </results>
</dir>

I can not change the layout of the xml
From this xml I need to extract the name and date of each entry. I somewhat prefer them to be grouped together without the type/size in the result returned by my xpath function.

So to sum it up, I need(want) an output that looks a bit like this:

[0]
| – name: a file name 1
| – date: 2012-01-01

[1]
| – name: a file name 2
| – date: 2012-01-02
etc

Is this in any possible way even possible? or I am I stuck with just using a xmldocument parser in python? (using etree from lxml)

  • 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-05-31T04:55:53+00:00Added an answer on May 31, 2026 at 4:55 am

    I’m not sure this is what you would like, but:

    In [1]: from lxml.etree import parse
    
    In [2]: tree = parse('/tmp/test.xml')
    
    In [3]: for entry in tree.xpath('/dir/results/entrylist/entry'):
       ...:     print entry.xpath('name|date')
       ...:
    [<Element name at 0x2ce7d70>, <Element date at 0x2ce7dc0>]
    [<Element name at 0x2ce7dc0>, <Element date at 0x2ce7c30>]
    [<Element name at 0x2ce7c30>, <Element date at 0x2ce7d70>]
    

    AFAIK, XPath is for selecting nodes, not combining them, so I don’t think it can do all of the job for you.

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

Sidebar

Related Questions

I was trying to solve Project Euler problem 10 using python, but my program
I'm trying to solve the problem here but I don't know why my code
I am trying to solve the problem Secret Code on SPOJ , and it's
I'm trying to solve this problem, its not a homework question, its just code
I've been trying to solve this problem for a number of days now but
I am trying to solve the maxium flow problem for a graph using Ford–Fulkerson
Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):
Trying to solve this problem . I would like to learn how the bootstrapper
I'm trying to solve the problem of passing a 2-dimensional table into JavaScript AJAX
I am trying to solve this problem. I have a series of SELECT statements

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.