Display null values in XML file

Posted on 2007-08-01
Last Modified: 2013-11-18
I need to be able to display null database values in an XML generated file. Since contract below was null it displayed one tag in opposite. I need to be able to display

Do you know a way to do that.

  <TITLE>HArry Potter</TITLE>

Question by:munzer
    LVL 60

    Expert Comment

    by:Geert Bormans
    are two syntactical forms to indicate an empty element...
    they are exactly the same thing and most XML processors have their own default
    Most processors can't be enforced to pick one over the other whilst serialising.
    On the other hand, it should not matter:
    an XML processor should behave exactly the same on either form

    If you really need the expanded form over the shorter form
    you need to develop some sort of regex program to expand the empty tags



    Author Comment

    well i am printing the XML tags in oracle pl/sql.

    The xml output will be parsed by perl program. I though it is easier to code it so it looks for data between <CONTRACT> </CONTRACT>. If there is nothing then it will read it as null.

    I tried the NVL function to replace a NULL value with a string <CONTRACT></CONTRACT> but it did not work.
    XML does not seem to like the dispaly of nulls in expanded term.

    LVL 60

    Expert Comment

    by:Geert Bormans
    > XML does not seem to like the dispaly of nulls in expanded term.

    that is correct. Since the difference is only in syntax, not in meaning
    the usual default is the condenced form

    I understand from your writing that you are hacking yourself a pseudo XML parser using Perl regex
    it should not be too difficult to allow both forms (basically you should do that, since you can never know for sure that the Oracle serialiser doesn't change its behaviour in the next update)
    It might be an even better advice to simply use XPath to get the value, using the perl XML parser (eg libXML,



    Author Comment

    I am wirting the pl/sql program to print the XML file more like print text statement.  I am telling it to print
    <CONTRACTOR></CONTRACTOR>.  Apparently the browser interprets this as null and replace it with <CONTRACT\>

    But, let us forget about PERL. Is there a way I can have oracle show this in the output
    LVL 60

    Expert Comment

    by:Geert Bormans
    If there was a way, it would be a bad XML application.
    That is what I tried to tell you, since both forms have an identical meaning,
    the serialiser picks a form and that is what you have to work with

    I had some customers in the past that had their XML application build the same way your perl script would work
    so I had to do some nifty tricks to get too that point
    one thing you could try is to add an xml comment in between the two tags and hope it vanishes somewhere along the path

    but basically, make sure that whatever step comes after the XML creation,
    it can accept both forms



    Author Comment


    is not there 2 ways in perl or any other language to parse an XML file.

    The first one is to find the tags and locate the data between them.

    the seond is to have the XML parser parse the data for you.

    I think you are saying the XML parser in PERl will know that his field is empty by default.

    If you are parsing th efirst way, then you may run into issues

    LVL 60

    Expert Comment

    by:Geert Bormans
    You are correct about the two ways.

    1. using Perl regex to find the tags and see if there is data between the tags, or to take into account that it can be an empty tag
    You may run into issues with this if you don't write a safe regex
    It may be faster than parsing first
    I don't like threating XML with a non-XML aware tool, but sometimes it is your best short-cut

    2. use a XML parser
    parse the document, read out the value for <CONTRACT>
    and this value will be "" for both <CONTRACT/> and <CONTRACT></CONTRACT>

    If you are good at regexes and have never used the perl XML parser, you might consider 1.



    Author Comment

    Well what I am finding out is that oracle actually prints the null value tags in expanded term. I can see that un der "View source" and the perl output.

    THe shorter term is getting displayed by the browser. Apparently the browser applies its own internal cnversion befoer it displays the xml syntaz. I am wondering if there is a way around this.
    LVL 60

    Accepted Solution

    Well yes, I didn't know you were looking at it from a browser.
    Both IE and Firefox do some normalisation on the XML before showing it.
    This default behaviour can not be changed.

    The only way around it is to build your own XSLT plus javascript and override the internal XSLT plus javascript
    This is a lot of work, here is an example to give you an idea
    I think it is not worth the trouble at all

    seems you are lucky from the perl side of it



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Fetch XML Unions? 3 249
    Help with SimpleXML charts with PHP 4 47
    Live mode in DW, need to creae Session 4 33
    Error handling in PHP 5 38
    Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now