?
Solved

Display null values in XML file

Posted on 2007-08-01
9
Medium Priority
?
288 Views
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
<CONTRACT></CONTRACT>

Do you know a way to do that.



BOOK_NO>DD28001</BOOK_NO>
  <PRODUCER>ABC</PRODUCER>
  <CONTRACT />
  <TITLE>HArry Potter</TITLE>
  <AUTHOR>Plain</AUTHOR>

0
Comment
Question by:munzer
  • 5
  • 4
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19614812
<CONTRACT></CONTRACT> and <CONTRACT />
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

cheers

Geert
0
 

Author Comment

by:munzer
ID: 19618230
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.

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19618335
> 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)

cheers

Geert
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:munzer
ID: 19618818
well
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
<CONTRACT></CONTRACT>.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19618876
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

cheers

Geert
0
 

Author Comment

by:munzer
ID: 19619284
gertone:

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

correct?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19619537
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.

cheers

Geert
0
 

Author Comment

by:munzer
ID: 19621201
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.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 19623092
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
http://www.o-xml.org/examples/xsl/default.xsl
I think it is not worth the trouble at all

seems you are lucky from the perl side of it

cheers

Geert
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

840 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