?
Solved

dom parsing xml file

Posted on 2014-09-08
1
Medium Priority
?
95 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 2000 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 …
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. 
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

719 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