How to read empty tag value.

Suppose there is a tag name with values ,
<Name>Raj</Name>
I am able to read the tag value 'Raj' ..
But if the tag is like
<Name /> I am getting null pointer exception while reading the tags value..
I have put the reading part in a try catch block .Is there any other efficient way to do it.

try {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document doc = builder.parse(inputSource);
         NodeList list = doc.getElementsByTagName("*");
         for (int i=0; i<list.getLength(); i++) {
           Element element = (Element)list.item(i);
           NodeList fstNm = element.getChildNodes();
*//  Here is where i get null point exception because of tag being*
    *like <test/> ,whereas other tags have vakue like <test>value </test>*
           String check_null;
           try {
            check_null = (((Node) fstNm.item(0)).getNodeValue());
           catch(Exception ex) {
               check_null="";
           //System.out.println(element.getNodeName() + ":"  + ((Node) fstNm.item(0)).getNodeValue());
           //if((((Node) fstNm.item(0)).getNodeValue()) != null)
           hm.put(element.getNodeName(),check_null);
           //System.out.println(element.getNodeName() + ":"+ (((Node) fstNm.item(0)).getNodeValue()));
       catch (Exception ex) {
           System.out.println("Exception in PostPaidInfo Parsing") ;;
           System.err.println(ex.toString());
           return 1;
     }I have just caught the exception ,I want to know is there any other way . The null pointer exception arises not because of string being null , But because of the internal parsing.
Edited by: CulbOy on Apr 29, 2010 12:13 PM

Similar Messages

  • How to read repeated tag values using sql query

    Database version
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE 11.2.0.2.0 Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Question
    How to get repeated tag values?
    <TXLife>
    <TXLifeRequest>
    <TransRefGUID>10bc80e7d60e59b0:a134d0:10d7c4674ad:-7ffd</TransRefGUID>
    <TransType tc="1203">OLI_TRANS_TRNHLD</TransType>
    <TransExeDate>2011-02-27</TransExeDate>
    <TransExeTime>15:06:35</TransExeTime>
    <InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
    <InquiryView>
    <InquiryViewCode>PLANUPDATE_CHBM_1203A</InquiryViewCode>
    </InquiryView>
    <OLifE>
    <SourceInfo>
    <SourceInfoName>CHBM Admin Tool</SourceInfoName>
    </SourceInfo>
    <Activity id="Activity1" HoldingID="Holding1">
    <UserCode>User123</UserCode>
    <LastUpdate>2011-02-27</LastUpdate>
    <ActivityCode>CHBM10001</ActivityCode>
    <OLifEExtension VendorCode="0098" ExtensionCode="Activity">
    <ActivityExtension>
    <SubActivityCode>CHBM20002</SubActivityCode>
    <LastUpdateTime>15:06:35</LastUpdateTime>
    </ActivityExtension>
    </OLifEExtension>
    </Activity>
    <Holding id="Holding1">
    <HoldingTypeCode tc="6">Group Master Contract</HoldingTypeCode>
    <Purpose tc="36">Business Protection and Preservation</Purpose>
    <Policy>
    <CarrierAdminSystem>CHBM</CarrierAdminSystem>
    <PolNumber>CHB0001234</PolNumber>
    <OLifEExtension VendorCode="0098" ExtensionCode="Policy">
    <PolicyExtension>
    <BillingDetail>
    <PaymentMode tc="3">Quarterly</PaymentMode>
    <BillingOrder tc="1009800002">Employee ID</BillingOrder>
    </BillingDetail>
    <SalaryAllotment>12354333</SalaryAllotment>
    </PolicyExtension>
    </OLifEExtension>
    </Policy>
    <Attachment id="Attach1">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 4</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:05:45</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach2">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 3</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>1</Sequence>
    <CreationTime>16:01:54</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach3">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>P62350</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Note 2</Description>
    <AttachmentData>Enter notes on changes or edits to plan</AttachmentData>
    <AttachmentType tc="14">Note</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:02:23</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    </Holding>
    </OLifE>
    </TXLifeRequest>
    </TXLife>
    Expected output shoulb be like this
    Description AttachmentType AttachmentData
    Event 4 Transaction Log Event Log
    Event 3 Transaction Log Event Log
    Note 2 Note Enter notes on changes or edits to plan
    Please help me any one on this
    Edited by: LRAJESH on Apr 20, 2011 8:27 AM

    SELECT
    t2. Description des,
    t2.AttachmentType attty,
    t2.DateCreated DateCreated,
    t2.UserCode UserCode,
    t1.Planid Planid,
    t2.createdtime,
    t1.Ausercode Ausercode
    FROM (
    SELECT xData doc
    FROM dual
    ) temp_table,
    XMLTable ( '/TXLife/TXLifeRequest/OLifE' passing doc
    COLUMNS
    Planid varchar2(20) path 'Holding/Policy/PolNumber',
    AttachmentType xmltype path 'Holding//Attachment' ,
    Ausercode varchar2(20) path 'Activity/UserCode'
    ) t1,
    XMLTable
    '/Attachment'
    passing t1.AttachmentType
    columns
    Description varchar2(1000) path 'Description',
    AttachmentType varchar2(1000) path 'AttachmentType/@tc',
    DateCreated varchar2(20) path 'DateCreated',
    createdtime varchar2(20) path 'OLifEExtension/AttachmentExtension/CreationTime',
    UserCode varchar2(200) path 'UserCode'
    ) t2

  • How to read the tag values sent by PCo to MII transaction

    Hi everybody,
    I have an Agent created inside PCo and its listening to a data server. I have also created a notification object which triggers my MII Transaction (after certain condition is getting fulfilled).
    Now, I want to pass certain values from PCo to MII using the notification object. For this I have tried 2 options:
    1. I defined one input parameter in transaction of type 'XML'. But this did not work. When I used 'Tracer' to check the received values, it showed empty.
    2. Since XML variable did not work, I tried with 'String' variable. It worked but the entire input data was in 'String' format.
    Actually I used XML_Saver to save the string and given filename as '.xml'. When I opened that xml file, it was looking like this:
    <<unable to write XML here>>
    Considering the above 2nd option, how can I extract the particular 'Tag' values from XML string. Since the string is not in the format of 'Rowset/Row/Row', I cannot specifically assign/map those tag values to any other variable inside MII transaction.
    ===========

    Hi, I was trying to post the xml string. It was not possible yesterday (because, SDN editor has converted xml part into some irregular string).
    Now, I am trying to post the string by removing the special characters. Please try to understand it.
    Now, my question is how to retrieve the CDATA value 5599999999 using xpath. Please help.
    NotificationMessage
    Body
    Values
    Expression1 type xsd string
    CDATA 5599999999
      /Expression1
      /Values
      /Body
      Faults /
      /NotificationMessage

  • How to read Share Memeory values in Solaris 10 Kernel?

    How to read Share Memeory values in Solaris 10 Kernel?

    # ipcs
    IPC status from <running system> as of Tue Apr 8 15:39:50 BST 2008
    T ID KEY MODE OWNER GROUP
    Message Queues:
    Shared Memory:
    Semaphores:
    or review the output of
    # sysdef

  • WAD template with BSP Application - how to read selection screen values

    Hello,
    I've created Web template with Web Application Designer (WAD).
    I would like to extend  that page with BSP Application...
    Purpuse of this application is to read some information from tables
    on BW transaction server and display them within Web page.
    Question: How to read selection screen values from a Web template ?
    Thanks for any help,
    Pawel Borowiec

    Hi,
    The selection screen parameters will be on an inputField, so try and get the is of the inputfield generated by doing View source...
    And once you get the inputfield Id, you can read the value in the InputField(InF) by
    using the following code...!
    data : if_value type ref to cl_htmlb_inputfield.
    data : variable type string.
    if_value ?= cl_htmlb_manager=>get_data( request = request
                                                name    = 'inputField'
                                                id      = 'InF_ID_here'
           if if_value->value is not initial.
             variable  = if_value->value.
           endif.
    Hope this helps.
    <b><i>Do reward each useful answer..!</i></b>
    Thanks,
    Tatvagna.

  • How to read a tag of a video file

    i try to create an application that can read audio and video file with java.
    But my probleme now is that ican't read the tag of video file.
    can you help me about how to read the tag of video file like the duration of video and frame rate and the other information about the video file.Thanks

    i try to create an application that can read audio and video file with java.
    But my probleme now is that ican't read the tag of video file.
    can you help me about how to read the tag of video file like the duration of video and frame rate and the other information about the video file.Thanks

  • How to remove empty tags from XML

    Hello,
    I have a XML file which contains some empty tags and some values with "?". I need to remove all empty tags and tags which have a value "?".
    Sample Data:
    <a>
    <b></b>
    <c> Hello </c>
    <d>world ?</d>
    <e>oracle</e>
    </a>
    Expected result:
    <a>
    <c> Hello </c>
    <e>oracle</e>
    </a>
    Thank you for your time.
    Thanks,
    Edited by: 850749 on Apr 7, 2011 6:25 PM

    Dear Odie,
    May I make your example a bit more complicated by adding an additional complexType, please:
    ---Original ----
    <DEPT>
    <EMPID>1</EMPID>
    <EMPNAME>Martin Chadderton</EMPNAME>
    <SALARY>??</SALARY>
    <SALARYq></SALARYq>
    </DEPT>
    ----- New ----
    <DEPT>
    <EMPID>1</EMPID>
    <EMPNAME>Martin Chadderton</EMPNAME>
    <SALARY>??</SALARY>
    <SALARYq></SALARYq>
    <EMPLMNT_HISTORY>
    <DEVISION>1</DEVISION>
    <FROM_DATE>2011-01-01 </FROM_DATE>
    <TO_DATE></TO_DATE>
    </EMPLMNT_HISTORY>
    </DEPT>
    Your solution works perfectly for <SALARY>, but how would you suggest also to deal with <TO_DATE> ?
    Massive thanks for your help!
    N.B. Just to emphasise, in my case I have 3 levels (complexType > complexType > complexType) and many elements and I would like to know if there is any generic option to say
    to remove all the empty elements from the result, as it causes to the SSJ (Systinet) Webservice to crash.

  • How to remove empty tags from a config file

    Hi all,
    I have a task where we need to run a Java program to remove tags which do not contain ny information from the config files. The format of the file is as under:
    <roleManager>
         <providers>
              <add name="AspNetSqlRoleProvider" b03f5f7f11d50a3a" />
              <add name="AspNetWindowsTokenRoleProvider" PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
    </roleManager>
    <httpModules>
    </httpModules>
    In the above lines <roleManager> is a tag which contains some data, while <httpModules> is an empty tag and does not conatin any data. The resultant should be:
    <roleManager>
         <providers>
              <add name="AspNetSqlRoleProvider" b03f5f7f11d50a3a" />
              <add name="AspNetWindowsTokenRoleProvider" PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
    </roleManager>
    Please suggest how can we achieve this?
    Thanks in advance

    I ususally do that type of thing with a state machine... read a token, look for what is next, and if it's the closing token, I don't write it out. You have well defined opening token syntax and closing token syntax, so it should be relatively easy.

  • How to read the selected value of a dropdown list box

    Hello,
    I have 2 custom fields which are of type dropdown list on Accounts(CRMM_ACCOUNT) PCUI application details tab.I need to read the selected value of first dropdown list item,based on that second dropdown list will be populated.
    I know where to populate the dropdown list box,it is in FILL_DROPDOWN_LISTBOX.
    I dont know how to trap the selection made on dropdown list.
    PLease guide me on how to trap the dropdown list field selection value.
    Thanks in advance.
    Thirumala.

    Hello,
    Check what is done in standard for the fielf REGION which is inked to the country.
    Otherwise, you can do the following :
    - in field group customizing, for field 1, flag the 'send request' flag. So, when you change the value in this field via the dropdown, the MAC methods are immediately called.
    - Put the new value in a global variable (GV).
    - in the fill_dropdown_listbox method, get the value from this GV and based on it, filter the values for the dropdown of field 2.
    Hope this will help you,
    Regards,
    Frederic

  • How to remove empty tags respecting the schema contraints?

    Hi,
    I'm generating an XML document with XSLT. This document have some empty tags. My question is about to remove all empty tags only if they are defined as optionnals in the schema.
    Is this possible with the DOM?
    Thanks in advance,
    Philippe

    With DOM3 validation api, elements/attributes may be checked if they may be removed.
    -Check if the element is empty; getFirstChild() method returns null.
    -Check if the element may be removed with DOM 3 Validation API.

  • How to Read XML tags....

    Hi guys...
    Can any one here tell me how to read the XML tag in PL/SQL.
    In table Enquiry there are following fields.
    Id          number
    Status          varchar2(5)
    Request          XML
    Reply          XML
    Error          varchar2(10)
    Now the following XML will be in request column from the requester.
    I have to get the,
    ->request which is in BODY tag,
    ->ID number which is in from tag (its the persons unique ID to check his BILL)
    Fetch the request from the database and updates it into the REPLY field with the same syntax.
    <message>
    <to> 123 </to>
    <from>789</from>
    <body> unbill </body>
    <messagenumber> 01 </messagenumber>
    </message>
    Can any one have the solution to this, how can I read the XML tags, process & again inserts as an XML.
    Thanks.

    Maybe something like this will be a pointer...
    SQL> CREATE TABLE t AS
      2  select 1 as id, 'C' as status, XMLTYPE('<message><to>123</to><from>789</from><body>unbill</body><messagenumber>01</messagenumber></message>') as request, XMLTYPE('<reply/>') as reply, 'NO ERROR' as error from dual
      3  ;
    Table created.
    SQL>
    SQL> SELECT * from t;
            ID S
    REQUEST
    REPLY
    ERROR
             1 C
    <message><to>123</to><from>789</from><body>unbill</body><messagenumber>01</messagenumber></message>
    <reply/>
    NO ERROR
    SQL>
    SQL> UPDATE t
      2  SET reply = updateXML(request,'/message/body/text()','bill')
      3  ;
    1 row updated.
    SQL>
    SQL> SELECT * from t;
            ID S
    REQUEST
    REPLY
    ERROR
             1 C
    <message><to>123</to><from>789</from><body>unbill</body><messagenumber>01</messagenumber></message>
    <message><to>123</to><from>789</from><body>bill</body><messagenumber>01</messagenumber></message>
    NO ERROR
    SQL>

  • How to generate empty tag using XMLForest

    Hi,
    I am creating an XML document using XMLAgg, XMLForest and XMlElement functions.
    At some point I have an XMLForest embedded in the other XMLForest
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      XMLForest( tableAlias.col11 as "address1",
                 tableAlias.col12 as "address2",            
               ) as "items",
    )           and within the last one I have some expressions which are empty, so the XML tags are not generated, however I have to have an empty tags:
    <address2></address2>I tried to replace an expression using "NVL" or "DECODE", but the results were the same.
    I also tried to replace an embedded XMLForest with an XMLElement :
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      *XMLElement("items"*
                 *XMLElement("address1"),*
                 *XMLElement("address2")*
               *) as "items",*)           however it created 2 <items> tags :
        <items>
             <items>
                <address1>value</address1>
                <address2></address2>
             </items>
         </items> I am working with Oracle 11.2.0 db.
    Is there any way to generate an empty tag when using XMLForest function?
    thank you in advance.
    Edited by: user624274 on Apr 3, 2013 8:52 AM
    Edited by: user624274 on Apr 3, 2013 8:53 AM

    Hello Odie_63.
    Your argument is valid, but it does not mean the solution I provided is bad.
    If you are concerned about the size of the result, it is simple, you can use like:
    REPLACE(XMLForest( NVL(e.indicator, '#NULLValue#') as "col1",  NVL(e.participant_id, '#NULLValue#') as "col2").getClobVal(), '#NULLValue#', '')
    According to Oracle documentation, REPLACE is smart and will return a CLOB (not a varchar2) because it changes the type of return according to the type of the first parameter. So you will not have issues with size.
    I believe the first question was related to use the final result to record to a table or send to another system (to use as integration). If it will be used just in a select field, it does not matter if it is not there or if it is there as NULL, the select of the field will always return ''.
    Other hint, I never use xmltype to store on database, because it is not compatible with other databases or integration tools. I use CLOB because it is the natural serialization of the object and I can convert and work with it inside and outside Oracle.
    But that is up to the architect and/or developer. If the system is running only on Oracle and there is no integration, maybe xmltype will save a lot of time in conversions.
    Regards.
    Rodolpho

  • How to delete empty tags after xml-import

    Hello collegues,
    I'm totally new in this forum so excuse me if I make a mistake, but I've a little question.
    I've imported text and images with a xml-import but sometimes empty tags (the colored invisible blocks) are in my text, with the result that I can't Find/Change on double-returns.
    Does anybody know an awnser to this matter? I would love to write an apple-script that will find/change this so i don't have to look after all my pages.
    Thank you very much in advance.

    ThePictureCreator wrote:
    ...I can't Find/Change on double-returns.
    What's your search query? I think you should be able to, with either a grep find of "\r+" or a normal text find of "^p^p". InDesign pretends like the tag-holding characters aren't there for the purpose of search. But you will lose the empty elements along with the extra returns. Maybe that is the problem?
    Jeff

  • How to remove empty tag.

    Hi,
    I have a scenario IDOC-XI-JDBC
    From IDOC we are using change pointers and when something has been changed then those fields are being sent out but other few empty fields were coming out and to avoid that I used mapWithDefault to avoid the empty tags as  target system used to error out.
    But now when any field is empty coming from change pointer is also being caught in mapWithDefault....whereas it is expected to send blank.
    Can anyone of you suggest any solution.
    Regards
    Ria

    Hi Ria,
    You can use if without else and check the field exist or not in the source and then map it to target.
    This is a bit tricky & if you dont feel comfortable with it, then use advanced UDF, and explicitely check ResultList.SUPPRESS object and remove it in UDF and form an output stream.
    You can use any of the two.
    Regards,
    Shri.
    <removed by moderator>
    Edited by: Mike Pokraka on Jul 28, 2008 5:05 PM

  • How to read ID3-tags

    Hi,
    Is there somebody who can explain me how to read ID3tags from a mp3-file.
    I searched whole google and didn't find a clear explanation.
    Sorry for my bad english.
    Maybe someone got an example?
    Thnx

    The source contains examples:
    http://www.ueberdosis.de/java/id3/download.html
    regards
    Christian

Maybe you are looking for

  • IDOC TO FILE ( PRODUCTION ORDER CREATED IN R/3 (LOIPRO01 Idoc) IS SENT 2 XI

    PLS...I NEED SOLUTION AS SOON AS POSSIBLE When a production order is created and is  released in R/3,the idoc (LOIPRO01 Idoc) should be passed (sent) to xi system and mapped into a file using FILEADAPTER.      Source :   SAP ERP ( LOIPRO01 Idoc)     

  • Imac and Macbook Pro (dream) configurations

    I am buying an Imac and a Macbook Pro. I edit with the entire Premiere Production Suite CS5.5. Right now I am using a 2008 white Macbook, which I brought to its deathbed by editing a 40 minute documentary on- so I know anything will be better than wh

  • Tv losing channels when vision box turned on

    When vision box is turned on I lose channels - film4 and radio channels and screen pixelates on others. Not actually watching channels through box, just on tv. Screen says no signal. As soon as box turned off signal returns. When scanning for channel

  • Media drive

    hi,I am trying to find model no of pocket media drive for the touchsmart IQ810uk desktop,hp support do not seem able to help,is there anyone in the community able to help??????

  • Comodo certs

    when I run through https://testconnectivity.microsoft.com and do the Lync test for logging in we get: Couldn't sign in. Error: Error Message: A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provid