The string below when I try to convert strElem (String) using Element newElement = (Element) DocumentHelper.parseText(strElem).getRootElement().detach(); It throws exception. Any idea what is wrong with the string? Or any workaround?
STRING: "<JposEntry logicalName="i6550_form1"> <creation factoryClass="com.ingenico.jpos.services.IngenicoServiceInstanceFactory" serviceClass="com.ingenico.jpos.services.i6k.FormService"/> <vendor name="Ingenico" url="http://www.ingenico-us.com"/> <jpos category="Form" version="1.7.250"/> <product description="Ingenico JavaPOS(TM) Form Service for Ingenico 6550" name="Ingenico JavaPOS for Ingenico 6550" url="http://www.ingenico-us.com"/> <!--IP Address and Port properties--> <prop name="ipaddress" type="String" value="999.999.999.1"/> <prop name="port" type="Integer" value="5555"/> <!--Forms--> <prop name="Idle" type="String" value="Idle.icg"/> <prop name="PinEntry" type="String" value="pin.icg"/> <prop name="OptOutCredit" type="String" value="OptOutC.icg"/> <prop name="OptOutDebit" type="String" value="OptOutD.icg"/> <prop name="SelectTenderTypeCreditDebit" type="String" value="tt_CD.icg"/> <prop name="SelectTenderTypCreditAndDebitAndEbt" type="String" value="tt_CDE.icg"/> <prop name="AmountConfirm" type="String" value="amt.icg"/> <prop name="SwipeCard" type="String" value="SwipeCrd.icg"/> <prop name="SelectCashBack" type="String" value="cashBack.icg"/> <prop name="EBTTenderTypeSelection" type="String" value="EBT_Sel.icg"/> <prop name="ItemDisplay" type="String" value="item.icg"/> <prop name="AuthDisplay" type="String" value="auth.icg"/> <prop name="ReSwpCrd" type="String" value="reswpcrd.icg"/> <!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )--> <prop name="clearScreen" type="Boolean" value="false"/> <prop name="eftlver" type="String" value="0220"/> <prop name="portName" type="String" value="COM1"/> <prop name="stopBits" type="String" value="1"/> <prop name="dataBits" type="String" value="8"/> <prop name="ConfigPath" type="String" value="./conf/i6k/"/> <prop name="eftpver" type="String" value="0220"/> <prop name="loopInterval" type="Integer" value="15"/> <prop name="mac" type="Boolean" value="false"/> <prop name="attribute" type="Byte" value="0"/> <prop name="optimize" type="Boolean" value="false"/> <prop name="flowControl" type="String" value="Xon/Xoff"/> <prop name="parity" type="String" value="None"/> <prop name="baudRate" type="String" value="19200"/> <prop name="deviceBus" type="String" value="RS232"/> <prop name="ShowSplash" type="Boolean" value="true"/> <prop name="conn" type="Integer" value="2"/> <prop name="timeOut" type="Integer" value="120000"/> <prop name="font" type="Byte" value="2"/> <prop name="connLib" type="String" value="./lib/usbj.dll"/> <prop name="backlight" type="Byte" value="0"/> </JposEntry><JposEntry logicalName="i6550_msr1"> <creation factoryClass="com.ingenico.jpos.services.IngenicoServiceInstanceFactory" serviceClass="com.ingenico.jpos.services.i6k.MSRService"/> <vendor name="Ingenico" url="http://www.ingenico-us.com"/> <jpos category="MSR" version="1.7.250"/> <product description="Ingenico JavaPOS(TM) MSR Service for Ingenico 6550 ISO Magnetic Strip Readers" name="Ingenico JavaPOS for Ingenico 6550" url="http://www.ingenico-us.com"/> <!--IP Address and Port properties--> <prop name="ipaddress" type="String" value="999.999.999.1"/> <prop name="port" type="Integer" value="5555"/> <!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )--> <prop name="clearScreen" type="Boolean" value="false"/> <prop name="portName" type="String" value="COM1"/> <prop name="dataBits" type="String" value="8"/> <prop name="conn" type="Integer" value="2"/> <prop name="parity" type="String" value="None"/> <prop name="flowControl" type="String" value="Xon/Xoff"/> <prop name="stopBits" type="String" value="1"/> <prop name="connLib" type="String" value="./lib/usbj.dll"/> <prop name="timeOut" type="Integer" value="100000"/> <prop name="deviceBus" type="String" value="RS232"/> <prop name="cpem" type="Integer" value="0"/> <prop name="baudRate" type="String" value="19200"/> <prop name="disableMsr" type="Boolean" value="false"/> </JposEntry><JposEntry logicalName="i6550_pp1"> <creation factoryClass="com.ingenico.jpos.services.IngenicoServiceInstanceFactory" serviceClass="com.ingenico.jpos.services.i6k.PINPadService"/> <vendor name="Ingenico" url="http://www.ingenico-us.com"/> <jpos category="PINPad" version="1.7.250"/> <product description="Ingenico JavaPOS(TM) PINPad Service for Ingenico 6550 Touch Screen" name="Ingenico JavaPOS for Ingenico 6550" url="http://www.ingenico-us.com"/> <!--IP Address and Port properties--> <prop name="ipaddress" type="String" value="999.999.999.1"/> <prop name="port" type="Integer" value="5555"/> <!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )--> <prop name="clearScreen" type="Boolean" value="false"/> <prop name="PPAD_MSG_APPROVED" type="String" value="Request APPROVED"/> <prop name="dataBits" type="String" value="8"/> <prop name="backlight" type="Byte" value="0"/> <prop name="portName" type="String" value="COM1"/> <prop name="PPAD_MSG_AMOUNTOK" type="String" value="Amount OK?"/> <prop name="deviceBus" type="String" value="RS232"/> <prop name="baudRate" type="String" value="19200"/> <prop name="PPAD_MSG_CANCELED" type="String" value="Request CANCELLED"/> <prop name="keyIndex" type="Byte" value="0"/> <prop name="PPAD_MSG_SELECTCARDTYPE" type="String" value="Select Card Type: Debit/Credit/Smart Card"/> <prop name="connLib" type="String" value="./lib/usbj.dll"/> <prop name="PPAD_MSG_ENTERVALIDPIN" type="String" value="Enter Valid PIN"/> <prop name="timeOut" type="Integer" value="100000"/> <prop name="PPAD_MSG_SLIDE_CARD" type="String" value="Please Slide Card"/> <prop name="PPAD_MSG_IDLE" type="String" value="The System is Idle"/> <prop name="PPAD_MSG_RETRIESEXCEEDED" type="String" value="Max Tries for PIN Entry Exceeded"/> <prop name="PPAD_MSG_ENTERPIN" type="String" value="Please Enter Your PIN"/> <prop name="pinTimeout2" type="Byte" value="15"/> <prop name="mac" type="Boolean" value="false"/> <prop name="pinTimeout1" type="Byte" value="15"/> <prop name="PPAD_MSG_NOTREADY" type="String" value="Not Ready"/> <prop name="conn" type="Integer" value="2"/> <prop name="parity" type="String" value="None"/> <prop name="stopBits" type="String" value="1"/> <prop name="PPAD_MSG_DECLINED" type="String" value="Request Declined- EFT Transaction Host"/> <prop name="PPAD_MSG_INSERTCARD" type="String" value="Insert Smart Card"/> <prop name="PPAD_MSG_PLEASEWAIT" type="String" value="Processing. Please Wait..."/> <prop name="flowControl" type="String" value="Xon/Xoff"/> </JposEntry><JposEntry logicalName="i6550_sg1"> <creation factoryClass="com.ingenico.jpos.services.IngenicoServiceInstanceFactory" serviceClass="com.ingenico.jpos.services.i6k.SignatureCaptureService"/> <vendor name="Ingenico" url="http://www.ingenico-us.com"/> <jpos category="SignatureCapture" version="1.7.250"/> <product description="Ingenico JavaPOS(TM) SignatureCapture Service for Ingenico 6550 Touch Screen" name="Ingenico JavaPOS for Ingenico 6550" url="http://www.ingenico-us.com"/> <!--IP Address and Port properties--> <prop name="ipaddress" type="String" value="999.999.999.1"/> <prop name="port" type="Integer" value="5555"/> <!--Forms--> <prop name="Sigform" type="String" value="Sigform.icg"/> <!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )--> <prop name="clearScreen" type="Boolean" value="false"/> <prop name="download" type="Boolean" value="false"/> <prop name="dataBits" type="String" value="8"/> <prop name="backlight" type="Byte" value="0"/> <prop name="portName" type="String" value="COM1"/> <prop name="eftpver" type="String" value="0220"/> <prop name="deviceBus" type="String" value="RS232"/> <prop name="baudRate" type="String" value="19200"/> <prop name="sigline" type="Boolean" value="false"/> <prop name="connLib" type="String" value="./lib/usbj.dll"/> <prop name="timeOut" type="Integer" value="30000"/> <prop name="eftlver" type="String" value="0220"/> <prop name="sigStart" type="Byte" value="99"/> <prop name="ConfigPath" type="String" value="./conf/i6k/"/> <prop name="conn" type="Integer" value="2"/> <prop name="parity" type="String" value="None"/> <prop name="stopBits" type="String" value="1"/> <prop name="sigTotal" type="Byte" value="30"/> <prop name="optimize" type="Boolean" value="true"/> <prop name="flowControl" type="String" value="Xon/Xoff"/> </JposEntry>" org.dom4j.DocumentException: Error on line 48 of document : Illegal character at end of document, <. Nested exception: Illegal character at end of document, <. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278) at XMLUtil.createIjposElements(XMLUtil.java:265) at PCDeploymentUtility.generateIjposFile(PCDeploymentUtility.java:255) at PCDeploymentUtility.createXMLFiles(PCDeploymentUtility.java:217) at PCDeploymentUtility.main(PCDeploymentUtility.java:287) Nested exception: org.xml.sax.SAXParseException: Illegal character at end of document, <. at org.apache.crimson.parser.Parser2.fatal(Unknown Source) at org.apache.crimson.parser.Parser2.fatal(Unknown Source) at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source) at org.apache.crimson.parser.Parser2.parse(Unknown Source) at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278) at XMLUtil.createIjposElements(XMLUtil.java:265) at PCDeploymentUtility.generateIjposFile(PCDeploymentUtility.java:255) at PCDeploymentUtility.createXMLFiles(PCDeploymentUtility.java:217) Thanks, Devang -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Devang Joshi Sent: Tuesday, March 20, 2007 1:33 PM To: Evan Kirkconnell; dom4j-user@lists.sourceforge.net Subject: Re: [dom4j-user] How to clone multilple Elementsin a Document I want to do following in a FOR loop i.e. 1. Get the FOUR elements under <JposEntries> from xml file below. 2. Copy them to some dom4j element(??? Which one to use???) 3. convert that element to string and do some string manipulation 4. Covert that string back to dom4j element 5. Insert that element at the end in <JposEntries> 6. Repeat step 1. (But now the doc will have 8 elements under <JposEntries> Thanks, Devang -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Evan Kirkconnell Sent: Monday, March 19, 2007 4:20 PM To: dom4j-user@lists.sourceforge.net Subject: Re: [dom4j-user] How to clone multilple Elementsin a Document Devang, If the <JposEntries> tag is the element "jPosEntries", then you can do this: someOtherElement.content().addAll( ( (Element)jPosEntries.clone() ).content() ); And all the children of the "jPosEntries" element would be cloned and made children of the "someOtherElement" element. You could also do it iteratively: for(int i=0; i<jPostEntries.content().size(); i++) someOtherElement.add( ( (Node)jPosEntries.content().get(i) ).clone() ); --Evan Devang Joshi wrote: > > Below is my xml file. The root is JposEntries and it has 4 elements > (JposEntry) > > I want to make a clone of 4 elements inside my root element. How do I > do that? I know how to make a clone of an element but how to go @ this > one? > > > > <?xml version="1.0" encoding="UTF-8"?> > > <JposEntries> > > > > <JposEntry logicalName="i6550_form1"> > > <prop name="ItemDisplay" type="String" value="item.icg"/> > > </JposEntry> > > > > <JposEntry logicalName="i6550_msr1"> > > <prop name="disableMsr" type="Boolean" value="false"/> > > </JposEntry> > > > > <JposEntry logicalName="i6550_pp1"> > > <prop name="flowControl" type="String" value="Xon/Xoff"/> > > </JposEntry> > > > > <JposEntry logicalName="i6550_sg1"> > > <prop name="flowControl" type="String" value="Xon/Xoff"/> > > </JposEntry> > > > > </JposEntries> > > > > Thanks, > > Devang > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Devang > Joshi > Sent: Tuesday, March 13, 2007 5:07 PM > To: dom4j-user@lists.sourceforge.net > Subject: [dom4j-user] How to remove Element from Document > > > > I am trying to delete first device element from my xml document. > > iterateToDevicePosition() function returns me the first device element, > > But doc.remove() did not work for me. (Note: doc has the parsed xml > > file) > > > > //Now delete the first device element > > Element dummyElem = iterateToDevicePosition(); > > //Now dummy element has the element I want to remove > > doc.remove(dummyElem); //This does not remove it from the doc??? > > > > Thanks, > > Devang > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Evan S. > > Kirkconnell > > Sent: Tuesday, March 13, 2007 7:52 AM > > To: dom4j-user@lists.sourceforge.net > > Subject: Re: [dom4j-user] convert String to Element > > > > (Element)DocumentHelper.parseText(xml).getRootElement().detach() > > > > As a forewarning, I think this creates the element in the null > > namespace. If you need it in the xhtml namespace, you may have to do a > > little more work. > > --Evan > > > > ----- Original Message ----- > > From: Devang Joshi <[EMAIL PROTECTED]> > > Date: Monday, March 12, 2007 4:44 pm > > Subject: [dom4j-user] convert String to Element > > To: dom4j-user@lists.sourceforge.net > > > > > I am trying to create clone of element then convert the element to > > > string. Do some string manipulation and then convert the string > > > back to > > > element. > > > > > > //***This will insert new elements inside the clone*** > > > Element newElement = (Element) currElement.clone(); > > > > > > //***We need to replace few values in the new element so convert to > > > string*** > > > String strElem = newElement.asXML(); > > > > > > // Do something with string (internal logic) > > > > > > How do I convert string to element and insert that in my xml > > > document????????????????????????? > > > > > > //this would put the element in the doc > > > this.insertElementAt(newElement, this.root.indexOf(currElement)+1); > > > > > > > > > > > > Thanks, > > > > > > Devang > > > > > > 972-550-2746 > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > - > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > > your > > opinions on IT & business topics through brief surveys-and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE > > V > > _______________________________________________ > > dom4j-user mailing list > > dom4j-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/dom4j-user > > > > ------------------------------------------------------------------------ - > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > > opinions on IT & business topics through brief surveys-and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE V > > _______________________________________________ > > dom4j-user mailing list > > dom4j-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/dom4j-user > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------ - > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE V > ------------------------------------------------------------------------ > > _______________________________________________ > dom4j-user mailing list > dom4j-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/dom4j-user > ------------------------------------------------------------------------ - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE V _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user ------------------------------------------------------------------------ - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE V _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user