Want to retrieve null value from xml?
i m writing this code to get the tag name and values from xml file.
Now the problem is that
if my xml file contain any tag whose value is not defined like
<root>
<firsttag>first</firsttag>
<Second></Second><Third>third</Third>
</root>
Now look if second tag doesnt contain anything ,then i want to add "null" to vector,but it throws null pointer exception because second tag is empty.
Vector<String> CSWFinfo = new Vector<String>();
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(xml));
Element root = doc.getDocumentElement();
NodeList node = root.getChildNodes();
for (int i = 0; i < node.getLength(); i++) {
Node currentNode = node.item(i);
if (isTextNode(currentNode))
continue;
CSWFinfo.addElement(currentNode.getNodeName());
if (null != currentNode.getFirstChild().getNodeValue()) {
CSWFinfo.addElement(currentNode.getFirstChild()
.getNodeValue());
} else {
CSWFinfo.addElement("null");
}//end of for loop block
System.out.println(CSWFinfo);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}I am using dom parser .
Can any one know how to do it????
Edited by: chauhan2003 on 16 Jun, 2008 12:06 PM
Are you sure that all currentNode have a firstChild ????
If your node has no value, it has no child
So i 'd change code to like look something like:
if (currentNode.getFirstChild() != null) {
CSWFinfo.addElement(currentNode.getFirstChild().getNodeValue());
} else {
CSWFinfo.addElement("null");
}
Similar Messages
-
Wants to eliminate null values from mapping queue
Hi All,
How can I eliminate null values from 'display queue' of a target mapping.
Can it be done through a UDF? Kindly help.
Because of null value, it is creating issue in the mapping logic.
Thanks,
JohnWe can remove null values using node functions.
Check the below thread:
Re: How to remove [] form Message Mapping Display Queue
Or
Try with the below UDF:
for (int i=0; i<a.length;i++)
if (! a<i>.equals(ResultList.SUPPRESS) || ! a<i>.equals(""))
result.addValue(a<i>);
Thanks, -
Value "null" is displayed when retrieving null values from database
Hi,
I'm retrieving a record from Oracle database using a ResultSet rs and displaying the values on screen. Some of the columns do not have any data.
The statements are:
ResultSet rs
st=con.createStatement();
rs=st.executeQuery(............)
out.println("<input name='punch_line' type='text' value='"+rs.getString(7)+"'>");
The problem is that there is no value in the database column rs.getString(7). Ideally when the value is null, the field should not display anything. But in my case it is displaying the text "null".
Can anyone let me know how can I display a blank value instead of displaying the text "null"?
Thanks,
Sridharapi >
String getString(int columnIndex)
Gets the value of the designated column in
column in the current row of this ResultSet object as
a String in the Java programming language.
so null is returned as string object..NO.
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html
Returns:
the column value; if the value is SQL NULL, the value returned is null
The Java literal null is returned, not the String "null". The JDBC API provides a method wasNull() to detect if the previous accessed column returned a SQL NULL. -
How to avoid the null values from xml publisher.
I am creating a report which have the claim numbers with the values CLA001,CLA111,null, null . when i preview my report it is showing some spaces for null values also. How can i avoid the spaces from the report.
I am giving for loop for the claim numbers in the template.
<?for-each:ROW?> <?sort:CLAIMNUMBER;'ascending';data-type='text'?>
<?CLAIMNUMBER?>
<?end for-each?>
Please help me out to solve this problem.
Thanks,
vasanth.Hi Sheshu,
According to your description, you are experiencing the null values and infinity values when browser the calculated measure, right?
Based on my research, the issue is caused by that dividing a non-zero or non-null value by zero or null. In this cases, we need to check for division by zero to avoid this situation. Here is the sample query for you reference.
IIF(
Measures.[Measure B]=0,null,
Measures.[Measure A] / Measures.[Measure B]
If you have any questions, please feel free to ask.
Regards,
Charlie Liao
TechNet Community Support -
Retrieving all values from hashmap in order you put them in
Hi guys,
I want to retrieve all values from a HashMap in the order I put them in.
So I can't use the values() method that gives back a collection and iterate over that.
Do you guys know a good way to do that ?You can just do something like this:
class OrderedMap
private final Map m_rep = new HashMap();
private final List m_keys = new ArrayList();
public Object get( final Object key )
return m_rep.get( key );
public Object put( final Object key, final Object value )
final Object result = m_rep.put( key, value );
if ( result != null )
m_keys.add( key );
return result;
public Object remove( final Object key )
final Object result = m_rep.remove( key );
if ( result != null )
m_keys.add( key );
return result;
public Iterator keyIterator()
return m_rep.iterator();
}Then use it like this:
for ( Iterator it = map.keyIterator(); it.hasNext(); )
final Object value = map.get( it.next() );
}This will be in the order you put them in. However, if you want to do this correctly, you should implement the Map interface and add all the methods. Another thing you can do is download the JDK 1.4 source, learn how they did and do it the same way for 1.2.
R. -
How to get string value from xml in JSF??
In JSF How to get string value from xml, .ini and properties file. I want to get string value from xml or text to JSF
Just use the appropriate API's for that. There are enough API's out which can read/parse/write XML, ini and properties files. E.g. JAXP or DOM4J for xml files, INI4J for ini files and Sun's own java.util.Properties for propertiesfiles.
JSF supports properties files as message bundle and resource bundle so that you can use them for error messages and/or localization. -
How to retrieve value from xml file
hi all,
can somebody pls tell me how to retrieve value from xml file using SAXParser.
I want to retrieve value of only one tag and have to perform some validation with that value.
it's urgent .
pls help me out
thnx in adv.
rituhi shanu,
the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
pls have a look at the following code snippet.
public class XMLValidator {
static ArrayList strXXX = new ArrayList();
public void validate(){
factory.setValidating(true);
parser = factory.newSAXParser();
//all factory code is here only
parser.parse(xmlURI, new XMLErrorHandler());
public void setXXX(String pstrXXX){
strUpn.add(pstrXXX);
public ArrayList getXXX(){
return strXXX;
class XMLErrorHandler extends DefaultHandler {
String tagName = "";
String tagValue = "";
String applicationRefNo = "";
String XXXValue ="";
String XXXNo = "";
XMLValidator objXmlValidator = new XMLValidator();
public void startElement(String uri, String name, String qName, Attributes atts) {
tagName = qName;
public void characters(char ch[], int start, int length) {
if ("Reference".equals(tagName)) {
tagValue = new String(ch, start, length).trim();
if (tagValue.length() > 0) {
RefNo = new String(ch, start, length);
if ("XXX".equals(tagName)) {
XXXValue = new String(ch, start, length).trim();
if (XXXValue.length() > 0) {
XXXNo = new String(ch, start, length);
public void endElement(String uri, String localName, String qName) throws SAXException {
if(qName.equalsIgnoreCase("XXX")) {
objXmlValidator.setXXX(XXXNo);
thnx & Regards,
ritu -
Need help Take out the null values from the ResultSet and Create a XML file
hi,
I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
null values to XML File. When i run the program it works alright and adds the null and not null values to
the file. But when i pass the boolean value to take out the null values it would not take it out and adds
the null and not null values.
Please look at the code i am posing. I am showing step by step where its not adding the null values.
Any help is always appreciated.
Thanks in advance.
============================================================================
Frame1 Class
============
public class Frame1 extends JFrame{
private JPanel contentPane;
private XQuery xQuery1 = new XQuery();
private XYLayout xYLayout1 = new XYLayout();
public Document doc;
private JButton jButton2 = new JButton();
private Connection con;
private Statement stmt;
private ResultSetToXML rstx;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
xQuery1.setSql("");
xQuery1.setUrl("jdbc:odbc:SCANODBC");
xQuery1.setUserName("SYSDBA");
xQuery1.setPassword("masterkey");
xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
jButton2.setText("Get XML from DB");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException ex) {
System.err.print("ClassNotFoundException: ");
System.err.println(ex.getMessage());
try {
con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
stmt = con.createStatement();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
void jButton2_actionPerformed(ActionEvent e) {
try{
OutputStream out;
XMLOutputter outputter;
Element root;
org.jdom.Document doc;
root = new Element("PINFO");
String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
ResultSet rs = stmt.executeQuery(query);
/*===========This is where i am passing the ResultSet and boolean=======
===========value to either add the null or not null values in the file======*/
rstx = new ResultSetToXML(rs,true);
} //end of try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
======================================================================================
ResultSetToXML class
====================
public class ResultSetToXML {
private OutputStream out;
private Element root;
private XMLOutputter outputter;
private Document doc;
// Constructor
public ResultSetToXML(ResultSet rs, boolean checkifnull){
try{
String tagname="";
String tagvalue="";
root = new Element("pinfo");
while (rs.next()){
Element users = new Element("Record");
for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
tagname= rs.getMetaData().getColumnName(i);
tagvalue=rs.getString(i);
System.out.println(tagname);
System.out.println(tagvalue);
/*============if the boolean value is false it adds the null and not
null value to the file =====================*/
/*============else it checks if the value is null or the length is
less than 0 and does the else clause in the if(checkifnull)===*/
if(checkifnull){
if((tagvalue == null) || tagvalue.length() < 0 ){
users.addContent((new Element(tagname).setText(tagvalue)));
else{
users.addContent((new Element(tagname).setText(tagvalue)));
else{
users.addContent((new Element(tagname).setText(tagvalue)));
root.addContent(users);
out=new FileOutputStream("c:/XMLFile.xml");
doc = new Document(root);
outputter = new XMLOutputter();
outputter.output(doc,out);
catch(IOException ioe){
System.out.println(ioe);
catch(SQLException sqle){Can someone please help me with this problem
Thanks. -
Re: [iPlanet-JATO] Re: Retrieving all Values from a Tiled View
Todd,
Let me try to explain you this time. I have a text field in a TiledViewBean.
When I display the page, the text field
html tag is created with the name="PageDetail.rDetail[0].tbFieldName" say
five times/rows with same name.
The html tags look like this.
<input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
maxlength=9 size=13>
<input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
maxlength=9 size=13>
<input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
maxlength=9 size=13>
When the form is submitted, I want to get the text field values using the
method getTbFieldName().getValues() which
returns an array object[]. This is in case where my TiledViewBean is not
bound and it is working fine.
Now in case when my TiledView is bound to a model, it creates the html tags
as follows.
<input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
maxlength=9 size=13>
<input type=text name="PageDetail.rDetail[1].tbFieldName" value=""
maxlength=9 size=13>
<input type=text name="PageDetail.rDetail[2].tbFieldName" value=""
maxlength=9 size=13>
Now when I say getTbFieldName().getValues() it returns only the first
element values in the object[] and the rest of the
values are null.
May be we need to create a utility method do get these values from
requestContext.
raju.
----- Original Message -----
From: Todd Fast <toddwork@c...>
Sent: Saturday, July 07, 2001 3:52 AM
Subject: Re: [iPlanet-JATO] Re: Retrieving all Values from a Tiled View
Raju.--
I wanted to know how the getValues() method works the reason being,
when the tiled view is NOT bound to a model, it populates all the
fields with the same name as some thing likeI'm afraid I don't understand your point--can you please clarify? Do you
mean "value" instead of "name"?
What are you trying to do? What behavior are you expecting but notseeing?
>
Without further clarification, I can say that the setValues() methodsNEVER
populates data on multiple rows of a (dataset) model, nor does it affect
multiple fields on the same row. Perhaps what you are seeing is theeffect
of default values. Model that derive from DefaulModel have the ability to
carry forward the values set on the first row to other rows in lieu ofdata
in those other rows. This behavior is for pure convenience and can be
turned off, and it is turned off for the SQL-based models.
Todd
[email protected]Hi,
I wanted to know how the getValues() method works the reason being,
when the tiled view is NOT bound to a model, it populates all the
fields with the same name as some thing like
PageDetail.rDetail[0].tbFieldValue
PageDetail.rDetail[0].tbFieldValue
in which case, the getValues() method works fine.
But in case where the tiled view is bound to a model, it populates
with different field names such as,
PageDetail.rDetail[0].tbFieldValue
PageDetail.rDetail[1].tbFieldValue
in this case, the getValues() doesn't work. Any soultion to this?
We are using Moko 1.1.1.
thanks in advance,
raju.
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
Does anyone know of is there a single method to get all values of a
display
field in a tiled view without having to iterate through all the
values ie
resetTileIndex() / nextTile() approach.
ie Something that returns an Object[] or Vector just like ND returned a
CspVector. I tried using the getValues() methods but that allways returns
a
single element array containing the first element.
(I think now, that method is used for multi selecteable ListBoxes)Actually, no. We can add this in the next patch, but for now, I'd recommend
creating a simple utility method to do the iteration on an arbitrary model
and build the list for you.
Todd -
Getting null values from nodes using DOMParser
Hi
I'm having problems retrieving the values from an XML doc.
I'm using the DOMParser, but instead of retrieving the values
from the nodes, I just get null.
Code fragment :
DOMParser parser = new DOMParser();
parser.parse(url);
XMLDocument doc = parser.getDocument();
NodeList nl = doc.getElementsByTagName("*");
Node n;
iNode = nl.getLength();
for (int i=0; i<iNode; i++)
n = nl.item(i);
String szNodeName = n.getNodeName();
System.out.print(szNodeName+ " (" );
System.out.print(n.getNodeValue()+")");
System.out.println();
The result is
course (null)
Name (null)
All the node names are correct, but the node values are NOT
displayed.
Any idea ?
Rodrigo
nullAccording to the DOM Level 1 spec, the "value" of an ELEMENT node
is null and the getNodeValue() method will always return null for
an ELEMENT type node. You have to get the TEXT children of an
element and then use the getNodeValue() method in the text nodes.
Oracle XML Team
Rodrigo Loureiro (guest) wrote:
: Hi
: I'm having problems retrieving the values from an XML doc.
: I'm using the DOMParser, but instead of retrieving the values
: from the nodes, I just get null.
: Code fragment :
: DOMParser parser = new DOMParser();
: parser.parse(url);
: XMLDocument doc = parser.getDocument();
: NodeList nl = doc.getElementsByTagName("*");
: Node n;
: iNode = nl.getLength();
: for (int i=0; i<iNode; i++)
: n = nl.item(i);
: String szNodeName = n.getNodeName();
: System.out.print(szNodeName+ " (" );
: System.out.print(n.getNodeValue()+")");
: System.out.println();
: The result is
: course (null)
: Name (null)
: All the node names are correct, but the node values are NOT
: displayed.
: Any idea ?
: Rodrigo
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
null -
Want to retrieve Account information from Siebel on demand thru web service
Hi
i have trial account on 'Siebel on demand' and want to retrieve the information from account or any object. There is one method mentioned in the 'OnDemWebSvcs.pdf' file as 'ContactQueryPage' ,but how to used this method is not clear.
So can any body give any pointer on this?
Thanks
YashHi,
Thanks for immd reply and it is really useful for new user like me.
I converted the wsdl file to java. Now suppose i want to fetch all the record from User object on SOD, i wrote the following code snippet but got error as Internal Error: Session is not available. Aborting Server.
Code : In java
private static String mstrUrl="https://secure-ausomxega.crmondemand.com/Services/Integration";
URL wsUrl = new URL(mstrUrl);
Default_BindingStub defaultBindingStubObject=new Default_BindingStub(wsUrl,null);
UserLocator []listOfUser=new UserLocator[1];
UserLocator userLocatorObject=new UserLocator();
//String xml ="<ListOfUser><User><FirstName /><UserLastName /><LastUpdated> (>='07/28/2004 06:30:00') AND (<='07/28/2009 06:45:00')</LastUpdated></User></ListOfUser>"
UserWS_UserQueryPage_Input("1","1",listOfUser1,"1");
UserWS_UserQueryPage_Input userWS_UserQueryPage_InputObject=new UserWS_UserQueryPage_Input("1","1",listOfUser,"1");
UserWS_UserQueryPage_Output userWS_UserQueryPage_OutputObject = defaultBindingStubObject.userQueryPage(userWS_UserQueryPage_InputObject);
Can any body provide any pointer on this, how to make a query in Siebel On Demand.
Thanks
Yash -
How to retrieve 2 values from a table in a LOV
Hi
I'm pretty new to APEX. I try to retrieve two values from a table using a LOV. I have a table named DEBIT with then columns SITE, NAME and KEY
I want to display NAME to the user in a list. When the user select an item from the list, I want to retrieve the data of the SITE and KEY column of this item in order to launch an SQL command based on this two values.
How to retrieve thes two values whant the user chooses an item from the list ?
I apologize for my english, being french.
Regards.
ChristianChristian,
From what I understood about your requirement, you want a 'select list with submit' which displays "NAME" and based on the value selected, you want to get the corresponding values for "SITE" and "KEY" from the table.
<b>Step 1: Create a select list with submit, say P1_MYSELECT </b><br><br>
Use something like this in the dynamic list of values for the select list: <br>
SELECT NAME display_value, NAME return_value
FROM DEBIT<br><br>
<b>Step 2: Create a page process of type PL/SQL block. Also create 2 hidden items P1_KEY and P1_SITE. </b><br><br>
In the PL/sQL, write something like:
DECLARE
v_key DEBIT.KEY%TYPE;
v_site DEBIT.SITE%TYPE;
CURSOR v_cur_myvals IS
SELECT KEY, SITE
FROM DEBIT
WHERE NAME = :P1_MYSELECT;
BEGIN
OPEN v_cur_myvals;
LOOP
FETCH v_cur_myvals
INTO v_key,v_site;
EXIT WHEN v_cur_myvals%NOTFOUND;
:P1_KEY := v_key;
:P1_SITE := v_site;
END LOOP;
CLOSE v_cur_myvals;
END; <br><br>
Then you can use these values for whatever purpose you need to.
Hope this helps. -
Eliminating the null values from popup list item
Dear All,
i create a popup list,at runtime it shows a null blank value among the values i specified while the combo box is not,
i want to eleminate the blank null value from the popup list.
Need Help.
Thanks & Regards.Okay,
i create a popup list, populate it in runtime with create_group_from_query builtin.
now when i run the form and click the list item, it display a null value among the other values which are
return from the create_group_from_query .
the procedure is below
procedure Department_proc is
rg recordgroup;
n number;
begin
remove_record_group('RG');------ this is another procedure which checks for Record group existance and remove it.
rg=:=create_group_from_query('RG4','SELECT NAME,TO_CHAR(DEPT_ID) FROM TAB_DEPT_SECTION
UNION
SELECT '||'''All Departments'''||'as name,'||'''0'''||' as name from dual');
n:=populate_group(rg4);
populate_list('control_block.department',rg4);
end;
it display a null value among the other values for the first time is run the form,but when i click it and select a value from it
and the onward click dont show the null value.i want to eleminate the null value even for the first time when the user run the
from.
Best Regards -
To extract null Values from the source in Infopackage selections - Very Urg
Hi All,
I need to pull the data which has null values from source. I tried to write routine by giving l_t_range-low = '' , space. nothing is working.
Please guide me with sample code.
Very Urgent.
Regards
ManoHi Mario.
Assuming that you want to avoid uploading of records having
zero for a keyfigure:
Create a startroutine for transfer rules and add this coding:
DELETE DATAPAK WHERE VALUE = '0'.
OR
LOOP AT DATAPAK.
IF DATAPAK-VALUE = 0..
DELETE DATAPAK.
ENDIF.
ENDLOOP.
'VALUE' represents the fieldname in transferstructure
Please let me know if i misundersttod the issue.
Regards
Joe -
Prevent null values from displaying in answers OBIEE 11g
Is there any possibilities in OBIEE to Prevent null values from displaying in answers
For example, If i have two records in table
TV cost=NULL(having agg rule sum in BMM layer)
RADIO cost=10(having agg rule sum in BMM layer)
in answers i get two records
TV NULL
RADIO 10
but i want to get one, only with not null costJust want to clarify your question,You want to eliminate the NULL values from the report am i right? If that is the case then put the filter COST <> NULL.
Do let me know the updates?
Thanks,
Maybe you are looking for
-
Problems installing the latest version of itunes, I've tried everything!
hello, I logged into my itunes a few days ago and clicked yes to upgrade to the latest verion. Ever since then, itunes will not open, I get a message saying 'itunes has encountered a problem and needs to close' I have searched through the support sit
-
How do I change the default search engine on the Mozill Start Page?
Yahoo has hijacked my start page search bar. I followed the advice in the answers to other yahoo related question, and now the start page search bar doesn't function at all and the upper search bar still default to yahoo.
-
My Adobe Application keeps crashing
Trying to install the creative cloud applications on my computer but my adobe application manager keeps crashing. I have CS6 trial installed on my computer right now. Using a Macbook pro
-
LR4 Print Draft PDF Color Problem
Win7 64 Ultimate LR4 PDF printer is Cute PDF PDf Reader is Foxit Reader My sytem is hardware color calibrated I have printed before in draft mode to PDF and the color output was fine. Recently, when I choose to print to PDF using draft mode, the outp
-
Hi, Facing an issue when Mixing, Room unbalance frequency (Hi-Mid strong, Weak Low frequency). Thinking of Add on an Active Studio Subwoofer. What's your suggestion? Or... any better idea? Appreciate!