Solved

dom parsing xml file

Posted on 2014-09-08
1
84 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now