Hi Rahul, Thank you for your help. I've modified my program to get the Nodes of Element type. Now, it's working properly. Once again, thank you for your help
Have a nice time, Thanks and Regards, Sreenivas Pitchuka Belgacom Towers - 03 P 200c boulevard Albert II 27, 1030 Brussels Tel: +32-2-202.73.56 -----Original Message----- From: Rahul Srivastava [mailto:[EMAIL PROTECTED] Sent: 15 May 2003 06:36 To: [EMAIL PROTECTED] Subject: RE: whitespace problem in parsing a xml file Hi Srinivasa, The ClassCastException says it all very clearly. Before that, you must know that all the whitespaces in a XML file are part of the corresponding DOM created, until, you have turned on the feature ignorable-whitespace, for which you must have an associated DTD grammar, to ignore these whitespaces. Now, the statement "nlRootChildNodes.item(0)" in line... > Element elFormCode = (Element)nlRootChildNodes.item(0); need not always be an Element. It can be a Text node. And that's where you are getting a ClassCastException. e.g. <parent> <child1> <child2> </parent> In the above case, the element "parent" has 5 childs viz. 1. Text Node (whitespaces) 2. Element Node (child1) 3. Text Node (whitespaces) 4. Element Node (child2) 5. Text Node (whitespaces) As you have mentioned, your program will work fine, if you do not have any whitespaces b/w the elements. So, you can choose, either to use the ignorable-whitespace feature, if you have a DTD OR to modify your program accordingly. Cheers, Rahul. > srinivasa-rao wrote... > > > Hi, > I'm using Xerces to parse a xml file. > It's able to read the xml file properly when there are no spaces > in the xml > file. But when I put spaces in the xml file, it's throwing the following > exception. > Here we'll open the xml file in xml spy and save it, it's automatically > adding the spaces. so I need to parse the xml file with spaces only) > java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl > > Part of parsing code is: > > DocumentBuilderFactory docBuilderFactory = > DocumentBuilderFactory.newInstance(); > DocumentBuilder docBuilder = > docBuilderFactory.newDocumentBuilder(); > Document oDocument = docBuilder.parse (new File(strFileName)); > oDocument.getDocumentElement().normalize(); > NodeList nlRoot = oDocument.getElementsByTagName("XMLMapping"); > NodeList nlRootChildNodes = > (org.w3c.dom.NodeList)(nlRoot.item(0).getChildNodes()); > Element elFormCode = (Element)nlRootChildNodes.item(0); > > Can anyone help me to solve this problem. > This is an urgent problem for me. > > Thanks in advance, > Sreenivas Pitchuka > > > Thanks and Regards, > > > > Sreenivas Pitchuka > > Belgacom Towers - 03 P 200c > > boulevard Albert II 27, 1030 Brussels > > Tel: +32-2-202.73.56 > > > > > -----Original Message----- > From: Mark Causer [mailto:[EMAIL PROTECTED] > Sent: 14 May 2003 16:04 > To: [EMAIL PROTECTED] > Subject: Running Xerces1 and 2 > > > Hi > > We have an existing application that uses JPOS drivers. These drivers > instantiate a DOMParser to parse the config files. > This code needs xerces.jar (version 1) to run. If I try using the xerces2 > jars , I get a java.lang.NoClassDefFoundError: > org/apache/xerces/framework/XMLParser thrown as the DOMParser's class > heirachy has changed in xerces2 > These drivers can not be changed. > As a mod for our own app I need to use the Grammar caching in > Xerces2 using > DOMParser... > > Anyone got any suggestions how I can use Both versions of the > DOMParser in > the same application....... > > thanks > > Mark Causer > PCMS Group PLC > > ________________________________________________________________________ > The information contained in this e-mail is intended only for the person > or entity to which it is addressed and may contain confidential and/or > privileged material. If you are not the intended recipient of this > e-mail, the use of this information or any disclosure, copying or > distribution is prohibited and may be unlawful. > > If you received this in error, please contact the sender and delete the > material from any computer. > > The views expressed in this e-mail may not necessarily be the views of > The PCMS Group plc and should not be taken as authority to carry out any > instruction contained. > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > **** DISCLAIMER **** > "This e-mail and any attachments thereto may contain information > which is confidential and/or protected by intellectual property > rights and are intended for the sole use of the recipient(s) > named above. > Any use of the information contained herein (including, but not > limited to, > total or partial reproduction, communication or distribution in > any form) > by persons other than the designated recipient(s) is prohibited. > If you have received this e-mail in error, please notify the > sender either > by telephone or by e-mail and delete the material from any computer. > Thank you for your cooperation." > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **** DISCLAIMER **** "This e-mail and any attachments thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by persons other than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation." --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
