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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:01:09+00:00 2026-06-14T02:01:09+00:00

I have s special xml file like below: <alarm-dictionary source=DDD type=ProxyComponent> <alarm code=402 severity=Alarm

  • 0

I have s special xml file like below:

<alarm-dictionary source="DDD" type="ProxyComponent">

    <alarm code="402" severity="Alarm" name="DDM_Alarm_402">
    <message>Database memory usage low threshold crossed</message>
    <description>dnKinds = database
    type = quality_of_service
    perceived_severity = minor
    probable_cause = thresholdCrossed
    additional_text = Database memory usage low threshold crossed
    </description>
    </alarm>

        ...
</alarm-dictionary>

I know in python, I can get the “alarm code”, “severity” in tag alarm by:

for alarm_tag in dom.getElementsByTagName('alarm'):
    if alarm_tag.hasAttribute('code'):
        alarmcode = str(alarm_tag.getAttribute('code'))

And I can get the text in tag message like below:

for messages_tag in dom.getElementsByTagName('message'):
    messages = ""
    for message_tag in messages_tag.childNodes:
        if message_tag.nodeType in (message_tag.TEXT_NODE, message_tag.CDATA_SECTION_NODE):
            messages += message_tag.data

But I also want to get the value like dnkind(database), type(quality_of_service), perceived_severity(thresholdCrossed) and probable_cause(Database memory usage low threshold crossed
) in tag description.

That is, I also want to parse the content in the tag in xml.

Could anyone help me with this?
Thanks a lot!

  • 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-14T02:01:11+00:00Added an answer on June 14, 2026 at 2:01 am

    Once you have the text from the description tag, it’s nothing to do with XML parsing. You just need do simple string-parsing to get the type = quality_of_service keys/values strings into something nicer to use in Python like a dictionary

    With some slightly simpler parsing thanks to ElementTree, it would look like this

    messages = """
    <alarm-dictionary source="DDD" type="ProxyComponent">
    
        <alarm code="402" severity="Alarm" name="DDM_Alarm_402">
        <message>Database memory usage low threshold crossed</message>
        <description>dnKinds = database
        type = quality_of_service
        perceived_severity = minor
        probable_cause = thresholdCrossed
        additional_text = Database memory usage low threshold crossed
        </description>
        </alarm>
    
            ...
    </alarm-dictionary>
    """
    
    import xml.etree.ElementTree as ET
    
    # Parse XML
    tree = ET.fromstring(messages)
    
    for alarm in tree.getchildren():
        # Get code and severity
        print alarm.get("code")
        print alarm.get("severity")
    
        # Grab description text
        descr = alarm.find("description").text
    
        # Parse "thing=other" into dict like {'thing': 'other'}
        info = {}
        for dl in descr.splitlines():
            if len(dl.strip()) > 0:
                key, _, value = dl.partition("=")
                info[key.strip()] = value.strip()
        print info
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem parsing a XML file which contains special characters like ,
I have following piece of code which tries to load an XML file from
I have an XML file with some lines like the following: <rule pat=&&&&&&&&&&&&&&&(?<B>B) ?(?<AND>&)
I have an xml file. <?xml version=1.0 encoding=UTF-8?> <channel> <item>content with special character é</item>
I have this code (part of bigger script): flashvars.xmlSource = datasource.xml; datasource.xml looks like:
Here is the XML I have in a file: SPECIAL NOTE: This is a
How to embed special character in XML and have XDocument parse it? <?xml version=1.0
I have an application that generates xml files, and they might contain special characters.
Is it possible to have special characters like åäö in the key? If i
I'd like to capitalize the first letter of a string which could have special

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.