Solved

dom parsing xml file

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

18 Experts available now in Live!

Get 1:1 Help Now