• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

Display null values in XML file

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>

  • 5
  • 4
1 Solution
Geert BormansInformation ArchitectCommented:
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


munzerAuthor Commented:
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.

Geert BormansInformation ArchitectCommented:
> 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, http://www.xml.com/pub/a/2001/11/14/xml-libxml.html)


Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

munzerAuthor Commented:
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
Geert BormansInformation ArchitectCommented:
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


munzerAuthor Commented:

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

Geert BormansInformation ArchitectCommented:
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.


munzerAuthor Commented:
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.
Geert BormansInformation ArchitectCommented:
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


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now