Link to home
Start Free TrialLog in
Avatar of munzer
munzer

asked on

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
<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>

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

<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
Avatar of munzer
munzer

ASKER

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.

> 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
Avatar of munzer

ASKER

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>.
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
Avatar of munzer

ASKER

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?
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
Avatar of munzer

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial