Solved

dom parsing xml file

Posted on 2014-09-08
1
92 Views
Last Modified: 2014-11-28
I am using DOM to parse an XML file. During the parsing process, the following function call is made:
date_transact = self.get_node_data(mynode.getElementsByTagName("transaction-date"))

wherein, get_node_data is defined as:

    def get_node_data(self, data_node):
        node_data  = None
        for subnode in data_node:
             if(subnode.firstChild != None):
                if subnode.firstChild.hasChildNodes():
                    node_data = subnode.firstChild.firstChild.data
                else:
                    node_data = subnode.firstChild.data
             else:
                node_data = subnode.nodeValue
        return node_data

ISSUE: the code above works if the transaction date value appears on the same line:
 <transaction-date> <date>20140401</date></transaction-date>

The retrieved date string is blank if the xml file lists different elements on different lines:
  <transaction-date>
    <date>20140401</date>
  </transaction-date>

Any thoughts as to why I am unable to retrieve the transaction date listed on a separate line?
0
Comment
Question by:cyber-33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
Jan Louwerens earned 500 total points
ID: 40340040
There may be child nodes that are simply text nodes containing the whitespace text.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question