Solved

dom parsing xml file

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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 …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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