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 7769811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:15:02+00:00 2026-06-01T16:15:02+00:00

I have some XML that I am parsing in python via lxml. I am

  • 0

I have some XML that I am parsing in python via lxml.

I am encountering situations where some elements have attributes and some don’t.

I need to extract them if they exist, but skip them if they don’t – I’m currently landing with errors (as my approach is wrong…)

I have deployed a testfornull, but that doesn’t work in all cases:

Code:

if root[0][a][b].attrib == '<>': 
 ByteSeqReference = "NULL"
else:
 ByteSeqReference = (attributes["Reference"])

XML A:

<ByteSequence Reference="BOFoffset">

XML B:

<ByteSequence Endianness = "little-endian" Reference="BOFoffset">

XML C:

<ByteSequence Endianness = "little-endian">

XML D:

 <ByteSequence>

My current method can only deal with A, B or D. It can not cope with C.

  • 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-01T16:15:03+00:00Added an answer on June 1, 2026 at 4:15 pm

    I’m surprised that a test for null values on an attribute which often won’t exist works ever — what you should be doing is checking whether it exists, not whether it’s empty:

    if 'Reference' in current_element.attrib:
      ...do something with it...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am parsing some XML that will have a link such as the following
I have some XML that I want to parse using the lxml method in
I have some data in a database that I need represented in an XML
I have an XML file that I would like to map some attributes of
I have a python script that parsing an xml file and is returning the
I have some XML that I'm parsing with a SAX parser in Java. It
I have some XML that I am parsing in jQuery. <payload> <value key=VehicleMake> <value
I have some xml files that contain text, which are displayed on my website.
I have some data in an XML element that looks like this: <?xml version=1.0
I have some code that uses Open XML to open up a .docx file,

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.