?
Solved

In PowerBuilder, how can i hide those tag in xml export file when there is a null value being returned from the datawindow?  E.g from the script below, <Name/><Initials>SRM</Initials>,  hide <Name/>

Posted on 2009-04-06
3
Medium Priority
?
1,160 Views
Last Modified: 2013-11-19
In PowerBuilder, how can i hide those tag in xml export file when there is a null value being returned from the datawindow?  
E.g from the script below, <Name/><Initials>SRM</Initials>,  i wish to hide <Name/> for being displayed in the XML file

Let me further explain my problems encountered in Powerbuilder Exported XML

Sample Scenario as below:
<Name>Johnson<MarriageDate>2001-09-09</MarriageDate></Name>
<Name>Marry<MarriageDate/></Name>
<Name>Jeannie<MarriageDate>2008-08-08</MarriageDate></Name>

Because MarriageDate element is expecting a date value, passing empty element <MarriageDate/> will cause validation error when importing the exported XML. Is there any way/workaround to resolve this to have output XML like sample below?

<Name>Johnson<MarriageDate>2001-09-09</MarriageDate></Name>
<Name>Marry</Name>
<Name>Jeannie<MarriageDate>2008-08-08</MarriageDate></Name>

0
Comment
Question by:orinauts
[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
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24174857
The simplest method to remove empty elements is to use XSLT. I don't know enough of PowerBuilder to do that by code, but if you know the basics, it seems that this article shows you how to do it: http://www.sybase.com/detail?id=1013844

Then I can help you with the XSLT part, which looks like this:

-- Abel --

<!-- ----------------------------------------------- -->
<!-- XSLT part, copies all except the empty elements -->
<!-- ----------------------------------------------- -->
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="xml" indent="yes"/>
    
    <!-- copy template, copies every element/node/text/attr -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>
 
    <!-- a "delete"-template to remove all contents of diffgr:before -->
    <xsl:template match="*[not(text())]" />
    
</xsl:stylesheet>
 
 
 
<!-- ----------------------------------------------- -->
<!-- your input (amended with a root to make it XML) -->
<!-- ----------------------------------------------- -->
<?xml version="1.0" encoding="utf-8"?>
<root>
    <Name>Johnson<MarriageDate>2001-09-09</MarriageDate></Name>
    <Name>Marry<MarriageDate/></Name>
    <Name>Jeannie<MarriageDate>2008-08-08</MarriageDate></Name>
</root>
 
 
 
<!-- --------------------------------- -->
<!-- the output after run against XSLT -->
<!-- --------------------------------- -->
<?xml version="1.0" encoding="utf-8"?>
<root>
    <Name>Johnson<MarriageDate>2001-09-09</MarriageDate></Name>
    <Name>Marry</Name>
    <Name>Jeannie<MarriageDate>2008-08-08</MarriageDate></Name>
</root>

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24174863
sorry for that wrong comment about diffgr:before, that was from something else. But it *is* a delete template and it removes all elements that do not contain any text content.
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 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