From netbeansfan at yahoo.com.au Fri Jan 2 05:50:10 2009 From: netbeansfan at yahoo.com.au (Jack Bush) Date: Fri Jan 2 05:50:16 2009 Subject: [jdom-interest] JDOM XSLT TransformerConfigurationException Message-ID: <277825.97829.qm@web59614.mail.ac4.yahoo.com> Hi All, I am getting the following exception when trying to do simple transformation (newbie in JDOM XSLT) using either XSLTransformer/TrAX in JDOM: ? javax.xml.transform.TransformerConfigurationException: java.io.EOFException: no more input at com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:121) at com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:120) at com.icl.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:72) at standaloneClientRemoteInvestmentBean.JDOMTrAXPojoInvestmentBean.retrieveAreaZipcode(JDOMTrAXPojoInvestmentBean.java:68) at standaloneClientRemoteInvestmentBean.JDOMTrAXPojoInvestmentBean.main(JDOMTrAXPojoInvestmentBean.java:37) Caused by: java.io.EOFException: no more input at com.icl.saxon.aelfred.XmlParser..popInput(XmlParser.java:4083) at com.icl.saxon.aelfred.XmlParser.pushURL(XmlParser.java:3620) at com.icl.saxon.aelfred.XmlParser.doParse(XmlParser.java:159) at com.icl.saxon.aelfred.SAXDriver.parse(SAXDriver.java:320) at com.icl.saxon.om.Builder.build(Builder.java:265) at com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:111) ... 4 more ? Below is the stateStyleSheet:

Transformed State Detail

Area Link Area Name
? The Java program that calls this stateStyleSheet is as follows: ??? SAXBuilder statesaxBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser", false); ??? org.jdom.Document stateDocument = statesaxBuilder.build("state.xml"); ??? TransformerFactory factory = TransformerFactory.newInstance(); ??? Transformer transformer = factory.newTransformer(new StreamSource("stateStyleSheet.xsl")); ??? JDOMSource source = new JDOMSource(stateDocument); ??? JDOMResult result = new JDOMResult(); ??? transformer.transform(source, result); ??? Document tranformedDocument = result.getDocument(); ??? ...... ? Could this exception have been caused by incorrectly formatted stateStyleSheet? The search path "/ns:html/ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a" has successfully worked in XPath such as the following lines: ? ??? XPath statePath = XPath.newInstance("/ns:html/ns:body/ns:div[@id='content']/ns:table [@class='sresults']/ns:tr/ns:td/ns:a"); ??? statePath.addNamespace("ns", http://www.w3.org/1999/xhtml); ? Whether including namespace ("ns") or not doesn't make any difference. I am running JDK1.6, Netbeans 6.1, JDOM 1.1, Saxon 6.5, TagSoup 1.2 on Windows XP platform. Your assistance would be much appreciated. Many thanks, Jack Stay connected to the people that matter most with a smarter inbox. Take a look http://au.docs.yahoo.com/mail/smarterinbox -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090102/8737f482/attachment.htm From jabba.laci at gmail.com Thu Jan 8 09:56:15 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu Jan 8 09:56:22 2009 Subject: [jdom-interest] JDOM and JSP Message-ID: <310fbb00901080956m5de92d78q6e54bcb832bc280e@mail.gmail.com> Hi, With JDOM I produce XHTML files that are also JSP files. I would like to do the following: " /> JSP should process the line to produce this: Here, "xf:submission" is a JDOM Element object. My concern is that JDOM transforms "<" to "<". Do you have an idea how to solve it? Thanks, Laszlo From jabba.laci at gmail.com Thu Jan 8 12:00:17 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu Jan 8 12:00:40 2009 Subject: [jdom-interest] JDOM and JSP In-Reply-To: <7E2E5BF2-ED27-4070-9257-08D06FD520AA@me.com> References: <310fbb00901080956m5de92d78q6e54bcb832bc280e@mail.gmail.com> <7E2E5BF2-ED27-4070-9257-08D06FD520AA@me.com> Message-ID: <310fbb00901081200q4b261c5m29801ef44b1b4ce5@mail.gmail.com> > If you're using JSP >= 2.0 (for example Tomcat >= 5.0), you can avoid that > old <%= notation. > > Instead, you can write: > > Hi, Thank you, I needed exactly this. However, instead of ${request.file}, we need to write ${param.file} (that's what I figured out). Thanks again, Laszlo From gepree at me.com Thu Jan 8 12:08:10 2009 From: gepree at me.com (Geoff Rimmer) Date: Thu Jan 8 12:08:20 2009 Subject: [jdom-interest] JDOM and JSP In-Reply-To: <310fbb00901080956m5de92d78q6e54bcb832bc280e@mail.gmail.com> References: <310fbb00901080956m5de92d78q6e54bcb832bc280e@mail.gmail.com> Message-ID: <95595556-A515-49F1-996F-74C6EDB06524@me.com> If you're using JSP >= 2.0 (for example Tomcat >= 5.0), you can avoid that old <%= notation. Instead, you can write: and this is now a valid piece of XML. See http://jcp.org/aboutJava/communityprocess/final/jsr152/index.html for details of the JSP 2.0 spec. Geoff On 8 Jan 2009, at 17:56, Jabba Laci wrote: > Hi, > > With JDOM I produce XHTML files that are also JSP files. I would like > to do the following: > > %>" /> > > JSP should process the line to produce this: > > > > Here, "xf:submission" is a JDOM Element object. My concern is that > JDOM transforms "<" to "<". Do you have an idea how to solve it? > > Thanks, > > Laszlo > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/ > youraddr@yourhost.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090108/d6e6ce92/attachment.htm From davidcw at MIT.EDU Fri Jan 9 02:14:50 2009 From: davidcw at MIT.EDU (David Cheng-Ping Wang) Date: Fri Jan 9 02:15:11 2009 Subject: [jdom-interest] Possible Bug/Feature with SAXBuilder's setExpandEntities() Message-ID: <200901091014.n09AEusv028298@outgoing.mit.edu> Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: jdomExpandEntitiesProblem.zip Type: application/zip Size: 1227 bytes Desc: not available Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20090109/c6041dd1/jdomExpandEntitiesProblem.zip From junk_mail at wp.pl Tue Jan 13 23:31:54 2009 From: junk_mail at wp.pl (junk_mail@wp.pl) Date: Tue Jan 13 23:32:07 2009 Subject: [jdom-interest] How to add two nodes with the same name on the same level? Message-ID: <496d94ea3da1f3.84413516@wp.pl> hi, Is it possible to add two nodes with the same name on the same level of xml file using .addcontent() method? I'm trying to do so and I get following error: Exception in thread "main" org.jdom.IllegalAddException: The Content already has an existing parent "tree"... Is there any way to disable that execption and force jdom to create two nodes with the same name? regards, sly ---------------------------------------------------- Gadaj? o tym wsz?dzie!!! SPRAWD? alefaceci.pl http://klik.wp.pl/?adr=www.alefaceci.pl&sid=607 From paul at activemath.org Wed Jan 14 00:37:10 2009 From: paul at activemath.org (Paul Libbrecht) Date: Wed Jan 14 00:37:23 2009 Subject: [jdom-interest] How to add two nodes with the same name on the same level? In-Reply-To: <496d94ea3da1f3.84413516@wp.pl> References: <496d94ea3da1f3.84413516@wp.pl> Message-ID: <9BFF0FA3-067E-4F7E-845D-18C37259B4CE@activemath.org> Sly, you need to duplicate them first. Element objects correspond to concrete elements in the tree since you can get parent or iterate through the list so you really have to make two different objects. Using clone() is an easy way to duplicate. After a case, you can addContent again. paul Le 14-janv.-09 ? 08:31, junk_mail@wp.pl a ?crit : > Is it possible to add two nodes with the same name on the same level > of > xml file using .addcontent() method? > > I'm trying to do so and I get following error: > > Exception in thread "main" org.jdom.IllegalAddException: The Content > already has an existing parent "tree"... > > Is there any way to disable that execption and force jdom to create > two > nodes with the same name? -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2203 bytes Desc: not available Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20090114/b4f65fd3/smime.bin From junk_mail at wp.pl Wed Jan 14 08:44:28 2009 From: junk_mail at wp.pl (junk_mail@wp.pl) Date: Wed Jan 14 08:44:54 2009 Subject: [jdom-interest] How to add two nodes with the same name on the same level? In-Reply-To: <496d94ea3da1f3.84413516@wp.pl> <9BFF0FA3-067E-4F7E-845D-18C37259B4CE@activemath.org> References: <496d94ea3da1f3.84413516@wp.pl> <9BFF0FA3-067E-4F7E-845D-18C37259B4CE@activemath.org> Message-ID: <496e166cb2f2f1.72275642@wp.pl> Thank You Paul!!! regards, sly ---------------------------------------------------- Czy Piotr Kupicha zadebiutuje na parkiecie? http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fs1.html&sid=613 From rick.softly at gmail.com Fri Jan 16 05:26:53 2009 From: rick.softly at gmail.com (Rick Avlonitis) Date: Fri Jan 16 05:27:02 2009 Subject: [jdom-interest] xmlOutputter question Message-ID: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> When I call xmlOutputter.output(docForPosting, http.getOutputStream()), this fails to update the data but I get: (Response Code: 200, Response Message: OK). But when I write the docForPosting to a file and then create a new document from the parsed file, I can successfully update the data (Response Code: 200, Response Message: OK). Why can I not put data successfully on the server with xmlOutputter.output(docForPosting, http.getOutputStream())? Your help will be appreciated. My code is below: package myJDom; > > import org.jdom.*; > import org.jdom.input.DOMBuilder; > import org.jdom.input.SAXBuilder; > import org.jdom.output.XMLOutputter; > import org.xml.sax.SAXException; > > import java.io.File; > import java.io.FileWriter; > import java.io.IOException; > import java.net.Authenticator; > import java.net.HttpURLConnection; > import java.net.URISyntaxException; > import java.net.URL; > import java.net.URLConnection; > import java.util.ArrayList; > import java.util.List; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > public class MyJDomParser { > protected List rawElementList = new ArrayList(); > protected List scrubbedElementList = new ArrayList(); > protected List newElementList = new ArrayList(); > protected SAXBuilder saxBuilder = new SAXBuilder(); > protected DOMBuilder domBuilder = new DOMBuilder(); > protected Document rawDoc = new Document(); > protected Element element; > > @SuppressWarnings("unchecked") > public void parseUrl() throws JDOMException, IOException { > System.out.println("preparing to parse the elements..."); > URL url = new URL( > " > http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036)"); > saxBuilder.setIgnoringElementContentWhitespace(true); > rawDoc = saxBuilder.build(url); > > element = rawDoc.getRootElement(); > rawElementList.addAll(element.getChildren()); > > for (int i = 0; i < 3; i++) {// remove 2 useless elements > rawElementList.remove(0); > } > > for (int i = 0; i < rawElementList.size(); i++) { > String s = rawElementList.get(i).getText(); > if (s != null && s != "") { > scrubbedElementList.add(rawElementList.get(i)); > } > } > > for (Element e : scrubbedElementList) { > System.out.println(e.getText()); > } > // for (Element e : rawElementList) { > // System.out.println(e.getText()); > // } > } > > public void getAllChangedElements() throws URISyntaxException { > System.out.println("preparing to change the data..."); > Element entry = new Element("entry"); > entry.addNamespaceDeclaration(Namespace.getNamespace("")); > newElementList.add(entry); > // rawElementList.add(entry); > > for (int i = 0; i < scrubbedElementList.size(); i++) { > String s = scrubbedElementList.get(i).getText(); > String name = scrubbedElementList.get(i).getName(); > if (s != null && s != "") { > if (name == "AccountName") { > s = "****55555******"; > } > Element e = new Element(name); > e.setText(s); > newElementList.add(e); > } > } > // return newData; > // for (Element e : newElementList) { > // System.out.println(e.getText()); > // } > } > > public void postData() throws IOException, JDOMException, > ParserConfigurationException, SAXException { > // building a document from DOM > DocumentBuilderFactory dbfac = > DocumentBuilderFactory.newInstance(); > DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); > org.w3c.dom.Document docPrepareToPost = docBuilder.newDocument(); > > // create my root element > org.w3c.dom.Element root = docPrepareToPost.createElement("entry"); > docPrepareToPost.appendChild(root); > > // add elements to my dom doc > for (int i = 0; i < newElementList.size(); i++) { > org.w3c.dom.Element child = docPrepareToPost > .createElement(newElementList.get(i).getName()); > child.setTextContent(newElementList.get(i).getText()); > root.appendChild(child); > } > > // parsing my doc from the file allows me a successful post > // FileWriter fs = new FileWriter("/home/rick/deleteme/crap2"); > // //posting is successful from this parsed file > // xmlOutputter.output(docForPosting, fs); > > DocumentBuilderFactory factory = > DocumentBuilderFactory.newInstance(); > docPrepareToPost = factory.newDocumentBuilder().parse( > new File("/home/rick/deleteme/crap2")); > > // setting up the stream > URL url = new URL( > " > http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036)"); > URLConnection connection = url.openConnection(); > connection.setDoOutput(true); > java.net.HttpURLConnection http = (HttpURLConnection) connection; > http.setRequestMethod("PUT"); > HttpURLConnection.setFollowRedirects(true); > http.setRequestProperty("Content-type", > "application/atom+xml;type=entry"); > > // creating a JDom doc from the DOM doc to facilitate streaming to > the > // server > org.jdom.Document docForPosting = > domBuilder.build(docPrepareToPost); > > XMLOutputter xmlOutputter = new XMLOutputter(); > //this fails to update the data (Response Code: 200, Response > Message: OK) > xmlOutputter.output(docForPosting, http.getOutputStream()); > //output seems ok > xmlOutputter.output(docForPosting, System.out); > //the printout seems ok > System.out.println("doctype = " + docForPosting.getDocType()); > //=null > FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); > //this successfully updates the data (Response Code: 200, Response > Message: OK) > xmlOutputter.output(docForPosting, file); > > System.out.println("Response Code: " + http.getResponseCode()); > System.out.println("Response Message: " + > http.getResponseMessage()); > } > > public static void main(String[] args) { > MyJDomParser parser = new MyJDomParser(); > Authenticator.setDefault(new MyAuthenticator()); > try { > parser.parseUrl(); > parser.getAllChangedElements(); > parser.postData(); > } catch (JDOMException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } catch (URISyntaxException e) { > e.printStackTrace(); > } catch (ParserConfigurationException e) { > e.printStackTrace(); > } catch (SAXException e) { > e.printStackTrace(); > } > } > } > *Output (snipped):* preparing to change the data... > > />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN > 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN > ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090116/45c4377c/attachment.htm From jhunter at servlets.com Fri Jan 16 15:26:40 2009 From: jhunter at servlets.com (Jason Hunter) Date: Fri Jan 16 15:26:51 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> Message-ID: <7D34A1D8-C91A-4861-98ED-A749F2079750@servlets.com> I'd try flushing the output stream to make the content actually go over the wire. If that's not it exactly, it's probably something like that. -jh- On Jan 16, 2009, at 5:26 AM, Rick Avlonitis wrote: > When I call xmlOutputter.output(docForPosting, > http.getOutputStream()), this fails to update the data but I get: > (Response Code: 200, Response Message: OK). > But when I write the docForPosting to a file and then create a new > document from the parsed file, I can successfully update the data > (Response Code: 200, Response Message: OK). > > Why can I not put data successfully on the server with > xmlOutputter.output(docForPosting, http.getOutputStream())? > > Your help will be appreciated. My code is below: > > > package myJDom; > > import org.jdom.*; > import org.jdom.input.DOMBuilder; > import org.jdom.input.SAXBuilder; > import org.jdom.output.XMLOutputter; > import org.xml.sax.SAXException; > > import java.io.File; > import java.io.FileWriter; > import java.io.IOException; > import java.net.Authenticator; > import java.net.HttpURLConnection; > import java.net.URISyntaxException; > import java.net.URL; > import java.net.URLConnection; > import java.util.ArrayList; > import java.util.List; > > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > > public class MyJDomParser { > protected List rawElementList = new ArrayList(); > protected List scrubbedElementList = new > ArrayList(); > protected List newElementList = new ArrayList(); > protected SAXBuilder saxBuilder = new SAXBuilder(); > protected DOMBuilder domBuilder = new DOMBuilder(); > protected Document rawDoc = new Document(); > protected Element element; > > @SuppressWarnings("unchecked") > public void parseUrl() throws JDOMException, IOException { > System.out.println("preparing to parse the elements..."); > URL url = new URL( > "http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) > "); > saxBuilder.setIgnoringElementContentWhitespace(true); > rawDoc = saxBuilder.build(url); > > element = rawDoc.getRootElement(); > rawElementList.addAll(element.getChildren()); > > for (int i = 0; i < 3; i++) {// remove 2 useless elements > rawElementList.remove(0); > } > > for (int i = 0; i < rawElementList.size(); i++) { > String s = rawElementList.get(i).getText(); > if (s != null && s != "") { > scrubbedElementList.add(rawElementList.get(i)); > } > } > > for (Element e : scrubbedElementList) { > System.out.println(e.getText()); > } > // for (Element e : rawElementList) { > // System.out.println(e.getText()); > // } > } > > public void getAllChangedElements() throws URISyntaxException { > System.out.println("preparing to change the data..."); > Element entry = new Element("entry"); > entry.addNamespaceDeclaration(Namespace.getNamespace("")); > newElementList.add(entry); > // rawElementList.add(entry); > > for (int i = 0; i < scrubbedElementList.size(); i++) { > String s = scrubbedElementList.get(i).getText(); > String name = scrubbedElementList.get(i).getName(); > if (s != null && s != "") { > if (name == "AccountName") { > s = "****55555******"; > } > Element e = new Element(name); > e.setText(s); > newElementList.add(e); > } > } > // return newData; > // for (Element e : newElementList) { > // System.out.println(e.getText()); > // } > } > > public void postData() throws IOException, JDOMException, > ParserConfigurationException, SAXException { > // building a document from DOM > DocumentBuilderFactory dbfac = > DocumentBuilderFactory.newInstance(); > DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); > org.w3c.dom.Document docPrepareToPost = > docBuilder.newDocument(); > > // create my root element > org.w3c.dom.Element root = > docPrepareToPost.createElement("entry"); > docPrepareToPost.appendChild(root); > > // add elements to my dom doc > for (int i = 0; i < newElementList.size(); i++) { > org.w3c.dom.Element child = docPrepareToPost > .createElement(newElementList.get(i).getName()); > child.setTextContent(newElementList.get(i).getText()); > root.appendChild(child); > } > > // parsing my doc from the file allows me a successful post > // FileWriter fs = new FileWriter("/home/rick/deleteme/ > crap2"); > // //posting is successful from this parsed file > // xmlOutputter.output(docForPosting, fs); > > DocumentBuilderFactory factory = > DocumentBuilderFactory.newInstance(); > docPrepareToPost = factory.newDocumentBuilder().parse( > new File("/home/rick/deleteme/crap2")); > > // setting up the stream > URL url = new URL( > "http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) > "); > URLConnection connection = url.openConnection(); > connection.setDoOutput(true); > java.net.HttpURLConnection http = (HttpURLConnection) > connection; > http.setRequestMethod("PUT"); > HttpURLConnection.setFollowRedirects(true); > http.setRequestProperty("Content-type", > "application/atom+xml;type=entry"); > > // creating a JDom doc from the DOM doc to facilitate > streaming to the > // server > org.jdom.Document docForPosting = > domBuilder.build(docPrepareToPost); > > XMLOutputter xmlOutputter = new XMLOutputter(); > //this fails to update the data (Response Code: 200, > Response Message: OK) > xmlOutputter.output(docForPosting, http.getOutputStream()); > //output seems ok > xmlOutputter.output(docForPosting, System.out); > //the printout seems ok > System.out.println("doctype = " + > docForPosting.getDocType()); //=null > FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); > //this successfully updates the data (Response Code: 200, > Response Message: OK) > xmlOutputter.output(docForPosting, file); > > System.out.println("Response Code: " + > http.getResponseCode()); > System.out.println("Response Message: " + > http.getResponseMessage()); > } > > public static void main(String[] args) { > MyJDomParser parser = new MyJDomParser(); > Authenticator.setDefault(new MyAuthenticator()); > try { > parser.parseUrl(); > parser.getAllChangedElements(); > parser.postData(); > } catch (JDOMException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } catch (URISyntaxException e) { > e.printStackTrace(); > } catch (ParserConfigurationException e) { > e.printStackTrace(); > } catch (SAXException e) { > e.printStackTrace(); > } > } > } > > Output (snipped): > > preparing to change the data... > > 0001-01-01T00:00:00+00:00 published>**------**</ > title><updated>2009-01-16T12:38:38+00:00</ > updated><AccountName>****55555******</ > AccountName><AccountNameUpper>**SHORTENED**</ > AccountNameUpper><CreateDate>2008-10-21T09:01:41+00:00</ > CreateDate><CreateUser>U6UJ9A000009</ > CreateUser><LastHistoryBy>ADMIN </ > LastHistoryBy><LastHistoryDate>2008-10-31T13:25:58+00:00</ > LastHistoryDate><ModifyDate>2009-01-16T12:38:38+00:00</ > ModifyDate><ModifyUser>ADMIN </ModifyUser><Status>Active</ > Status><Type>Corporate</Type><Prefix>Mr.</Prefix><Name>Bob</ > Name><Surname>Smith</Surname><Gender>Male</Gender><Idtype>I.D.</ > Idtype><Idpassportno>7904055766543</Idpassportno><Citizen>RSA</ > Citizen></entry> > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/ > youraddr@yourhost.com From joe.bowbeer at gmail.com Fri Jan 16 15:49:43 2009 From: joe.bowbeer at gmail.com (Joe Bowbeer) Date: Fri Jan 16 15:49:57 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> Message-ID: <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> I agree with Jason that you should close the output stream (which will also flush) before getting the response code. Also, if you're going to be doing a lot of http processing I recommend using Apache's httpclient instead of dealing with Java's HttpConnection directly. On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: > When I call xmlOutputter.output(docForPosting, http.getOutputStream()), > this fails to update the data but I get: (Response Code: 200, Response > Message: OK). > But when I write the docForPosting to a file and then create a new document > from the parsed file, I can successfully update the data (Response Code: > 200, Response Message: OK). > > Why can I not put data successfully on the server with > xmlOutputter.output(docForPosting, http.getOutputStream())? > > Your help will be appreciated. My code is below: > > > package myJDom; >> >> import org.jdom.*; >> import org.jdom.input.DOMBuilder; >> import org.jdom.input.SAXBuilder; >> import org.jdom.output.XMLOutputter; >> import org.xml.sax.SAXException; >> >> import java.io.File; >> import java.io.FileWriter; >> import java.io.IOException; >> import java.net.Authenticator; >> import java.net.HttpURLConnection; >> import java.net.URISyntaxException; >> import java.net.URL; >> import java.net.URLConnection; >> import java.util.ArrayList; >> import java.util.List; >> >> import javax.xml.parsers.DocumentBuilder; >> import javax.xml.parsers.DocumentBuilderFactory; >> import javax.xml.parsers.ParserConfigurationException; >> >> public class MyJDomParser { >> protected List<Element> rawElementList = new ArrayList<Element>(); >> protected List<Element> scrubbedElementList = new >> ArrayList<Element>(); >> protected List<Element> newElementList = new ArrayList<Element>(); >> protected SAXBuilder saxBuilder = new SAXBuilder(); >> protected DOMBuilder domBuilder = new DOMBuilder(); >> protected Document rawDoc = new Document(); >> protected Element element; >> >> @SuppressWarnings("unchecked") >> public void parseUrl() throws JDOMException, IOException { >> System.out.println("preparing to parse the elements..."); >> URL url = new URL( >> " >> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036)<http://192.168.1.199:3334/sdata/slx/dynamic/accounts%28A6UJ9A000036%29> >> "); >> saxBuilder.setIgnoringElementContentWhitespace(true); >> rawDoc = saxBuilder.build(url); >> >> element = rawDoc.getRootElement(); >> rawElementList.addAll(element.getChildren()); >> >> for (int i = 0; i < 3; i++) {// remove 2 useless elements >> rawElementList.remove(0); >> } >> >> for (int i = 0; i < rawElementList.size(); i++) { >> String s = rawElementList.get(i).getText(); >> if (s != null && s != "") { >> scrubbedElementList.add(rawElementList.get(i)); >> } >> } >> >> for (Element e : scrubbedElementList) { >> System.out.println(e.getText()); >> } >> // for (Element e : rawElementList) { >> // System.out.println(e.getText()); >> // } >> } >> >> public void getAllChangedElements() throws URISyntaxException { >> System.out.println("preparing to change the data..."); >> Element entry = new Element("entry"); >> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >> newElementList.add(entry); >> // rawElementList.add(entry); >> >> for (int i = 0; i < scrubbedElementList.size(); i++) { >> String s = scrubbedElementList.get(i).getText(); >> String name = scrubbedElementList.get(i).getName(); >> if (s != null && s != "") { >> if (name == "AccountName") { >> s = "****55555******"; >> } >> Element e = new Element(name); >> e.setText(s); >> newElementList.add(e); >> } >> } >> // return newData; >> // for (Element e : newElementList) { >> // System.out.println(e.getText()); >> // } >> } >> >> public void postData() throws IOException, JDOMException, >> ParserConfigurationException, SAXException { >> // building a document from DOM >> DocumentBuilderFactory dbfac = >> DocumentBuilderFactory.newInstance(); >> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >> org.w3c.dom.Document docPrepareToPost = docBuilder.newDocument(); >> >> // create my root element >> org.w3c.dom.Element root = >> docPrepareToPost.createElement("entry"); >> docPrepareToPost.appendChild(root); >> >> // add elements to my dom doc >> for (int i = 0; i < newElementList.size(); i++) { >> org.w3c.dom.Element child = docPrepareToPost >> .createElement(newElementList.get(i).getName()); >> child.setTextContent(newElementList.get(i).getText()); >> root.appendChild(child); >> } >> >> // parsing my doc from the file allows me a successful post >> // FileWriter fs = new FileWriter("/home/rick/deleteme/crap2"); >> // //posting is successful from this parsed file >> // xmlOutputter.output(docForPosting, fs); >> >> DocumentBuilderFactory factory = >> DocumentBuilderFactory.newInstance(); >> docPrepareToPost = factory.newDocumentBuilder().parse( >> new File("/home/rick/deleteme/crap2")); >> >> // setting up the stream >> URL url = new URL( >> " >> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036)<http://192.168.1.199:3334/sdata/slx/dynamic/accounts%28A6UJ9A000036%29> >> "); >> URLConnection connection = url.openConnection(); >> connection.setDoOutput(true); >> java.net.HttpURLConnection http = (HttpURLConnection) connection; >> http.setRequestMethod("PUT"); >> HttpURLConnection.setFollowRedirects(true); >> http.setRequestProperty("Content-type", >> "application/atom+xml;type=entry"); >> >> // creating a JDom doc from the DOM doc to facilitate streaming to >> the >> // server >> org.jdom.Document docForPosting = >> domBuilder.build(docPrepareToPost); >> >> XMLOutputter xmlOutputter = new XMLOutputter(); >> //this fails to update the data (Response Code: 200, Response >> Message: OK) >> xmlOutputter.output(docForPosting, http.getOutputStream()); >> //output seems ok >> xmlOutputter.output(docForPosting, System.out); >> //the printout seems ok >> System.out.println("doctype = " + docForPosting.getDocType()); >> //=null >> FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); >> //this successfully updates the data (Response Code: 200, Response >> Message: OK) >> xmlOutputter.output(docForPosting, file); >> >> System.out.println("Response Code: " + http.getResponseCode()); >> System.out.println("Response Message: " + >> http.getResponseMessage()); >> } >> >> public static void main(String[] args) { >> MyJDomParser parser = new MyJDomParser(); >> Authenticator.setDefault(new MyAuthenticator()); >> try { >> parser.parseUrl(); >> parser.getAllChangedElements(); >> parser.postData(); >> } catch (JDOMException e) { >> e.printStackTrace(); >> } catch (IOException e) { >> e.printStackTrace(); >> } catch (URISyntaxException e) { >> e.printStackTrace(); >> } catch (ParserConfigurationException e) { >> e.printStackTrace(); >> } catch (SAXException e) { >> e.printStackTrace(); >> } >> } >> } >> > > *Output (snipped):* > > preparing to change the data... >> <?xml version="1.0" encoding="UTF-8"?> >> <entry><entry >> /><published>0001-01-01T00:00:00+00:00</published><title>**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090116/594165ad/attachment.htm From rick.softly at gmail.com Mon Jan 19 01:15:22 2009 From: rick.softly at gmail.com (Rick Avlonitis) Date: Mon Jan 19 01:15:37 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> Message-ID: <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> Thank you for the inputs. However, I have to disagree. My problem can be distilled like so: If I create a document from an ArrayList and try to post, the server doesn't update. If I create a document by parsing the file made from a document that was made from ArrayList and post, the server updates. This makes me think that the http output stream is not at fault, since it works for the case for the document built from a parsed file. (I have also since wrapped the httpOutputStream in a bufferedStreamReader and called flush(). Still nothing). It makes me think that there is a setting which is read from the parsed file which is not read from the ArrayList. So the above makes me wonder if ArrayList is a suitable list to work with. What other container could I use? Regards, Rick On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: > I agree with Jason that you should close the output stream (which will also > flush) before getting the response code. > > Also, if you're going to be doing a lot of http processing I recommend > using Apache's httpclient instead of dealing with Java's HttpConnection > directly. > > > On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: > >> When I call xmlOutputter.output(docForPosting, http.getOutputStream()), >> this fails to update the data but I get: (Response Code: 200, Response >> Message: OK). >> But when I write the docForPosting to a file and then create a new >> document from the parsed file, I can successfully update the data (Response >> Code: 200, Response Message: OK). >> >> Why can I not put data successfully on the server with >> xmlOutputter.output(docForPosting, http.getOutputStream())? >> >> Your help will be appreciated. My code is below: >> >> >> package myJDom; >>> >>> import org.jdom.*; >>> import org.jdom.input.DOMBuilder; >>> import org.jdom.input.SAXBuilder; >>> import org.jdom.output.XMLOutputter; >>> import org.xml.sax.SAXException; >>> >>> import java.io.File; >>> import java.io.FileWriter; >>> import java.io.IOException; >>> import java.net.Authenticator; >>> import java.net.HttpURLConnection; >>> import java.net.URISyntaxException; >>> import java.net.URL; >>> import java.net.URLConnection; >>> import java.util.ArrayList; >>> import java.util.List; >>> >>> import javax.xml.parsers.DocumentBuilder; >>> import javax.xml.parsers.DocumentBuilderFactory; >>> import javax.xml.parsers.ParserConfigurationException; >>> >>> public class MyJDomParser { >>> protected List rawElementList = new ArrayList(); >>> protected List scrubbedElementList = new >>> ArrayList(); >>> protected List newElementList = new ArrayList(); >>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>> protected DOMBuilder domBuilder = new DOMBuilder(); >>> protected Document rawDoc = new Document(); >>> protected Element element; >>> >>> @SuppressWarnings("unchecked") >>> public void parseUrl() throws JDOMException, IOException { >>> System.out.println("preparing to parse the elements..."); >>> URL url = new URL( >>> " >>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>> "); >>> saxBuilder.setIgnoringElementContentWhitespace(true); >>> rawDoc = saxBuilder.build(url); >>> >>> element = rawDoc.getRootElement(); >>> rawElementList.addAll(element.getChildren()); >>> >>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>> rawElementList.remove(0); >>> } >>> >>> for (int i = 0; i < rawElementList.size(); i++) { >>> String s = rawElementList.get(i).getText(); >>> if (s != null && s != "") { >>> scrubbedElementList.add(rawElementList.get(i)); >>> } >>> } >>> >>> for (Element e : scrubbedElementList) { >>> System.out.println(e.getText()); >>> } >>> // for (Element e : rawElementList) { >>> // System.out.println(e.getText()); >>> // } >>> } >>> >>> public void getAllChangedElements() throws URISyntaxException { >>> System.out.println("preparing to change the data..."); >>> Element entry = new Element("entry"); >>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>> newElementList.add(entry); >>> // rawElementList.add(entry); >>> >>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>> String s = scrubbedElementList.get(i).getText(); >>> String name = scrubbedElementList.get(i).getName(); >>> if (s != null && s != "") { >>> if (name == "AccountName") { >>> s = "****55555******"; >>> } >>> Element e = new Element(name); >>> e.setText(s); >>> newElementList.add(e); >>> } >>> } >>> // return newData; >>> // for (Element e : newElementList) { >>> // System.out.println(e.getText()); >>> // } >>> } >>> >>> public void postData() throws IOException, JDOMException, >>> ParserConfigurationException, SAXException { >>> // building a document from DOM >>> DocumentBuilderFactory dbfac = >>> DocumentBuilderFactory.newInstance(); >>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>> org.w3c.dom.Document docPrepareToPost = docBuilder.newDocument(); >>> >>> // create my root element >>> org.w3c.dom.Element root = >>> docPrepareToPost.createElement("entry"); >>> docPrepareToPost.appendChild(root); >>> >>> // add elements to my dom doc >>> for (int i = 0; i < newElementList.size(); i++) { >>> org.w3c.dom.Element child = docPrepareToPost >>> .createElement(newElementList.get(i).getName()); >>> child.setTextContent(newElementList.get(i).getText()); >>> root.appendChild(child); >>> } >>> >>> // parsing my doc from the file allows me a successful post >>> // FileWriter fs = new FileWriter("/home/rick/deleteme/crap2"); >>> // //posting is successful from this parsed file >>> // xmlOutputter.output(docForPosting, fs); >>> >>> DocumentBuilderFactory factory = >>> DocumentBuilderFactory.newInstance(); >>> docPrepareToPost = factory.newDocumentBuilder().parse( >>> new File("/home/rick/deleteme/crap2")); >>> >>> // setting up the stream >>> URL url = new URL( >>> " >>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>> "); >>> URLConnection connection = url.openConnection(); >>> connection.setDoOutput(true); >>> java.net.HttpURLConnection http = (HttpURLConnection) connection; >>> http.setRequestMethod("PUT"); >>> HttpURLConnection.setFollowRedirects(true); >>> http.setRequestProperty("Content-type", >>> "application/atom+xml;type=entry"); >>> >>> // creating a JDom doc from the DOM doc to facilitate streaming >>> to the >>> // server >>> org.jdom.Document docForPosting = >>> domBuilder.build(docPrepareToPost); >>> >>> XMLOutputter xmlOutputter = new XMLOutputter(); >>> //this fails to update the data (Response Code: 200, Response >>> Message: OK) >>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>> //output seems ok >>> xmlOutputter.output(docForPosting, System.out); >>> //the printout seems ok >>> System.out.println("doctype = " + docForPosting.getDocType()); >>> //=null >>> FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); >>> //this successfully updates the data (Response Code: 200, >>> Response Message: OK) >>> xmlOutputter.output(docForPosting, file); >>> >>> System.out.println("Response Code: " + http.getResponseCode()); >>> System.out.println("Response Message: " + >>> http.getResponseMessage()); >>> } >>> >>> public static void main(String[] args) { >>> MyJDomParser parser = new MyJDomParser(); >>> Authenticator.setDefault(new MyAuthenticator()); >>> try { >>> parser.parseUrl(); >>> parser.getAllChangedElements(); >>> parser.postData(); >>> } catch (JDOMException e) { >>> e.printStackTrace(); >>> } catch (IOException e) { >>> e.printStackTrace(); >>> } catch (URISyntaxException e) { >>> e.printStackTrace(); >>> } catch (ParserConfigurationException e) { >>> e.printStackTrace(); >>> } catch (SAXException e) { >>> e.printStackTrace(); >>> } >>> } >>> } >>> >> >> *Output (snipped):* >> >> preparing to change the data... >>> >>> >> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>> >>> >> >> > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/4036b352/attachment.htm From joe.bowbeer at gmail.com Mon Jan 19 09:08:40 2009 From: joe.bowbeer at gmail.com (Joe Bowbeer) Date: Mon Jan 19 09:11:20 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> Message-ID: <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> What's the diff between the two documents created in the two different ways? Also, what's your root element? The snippet below looks like nothing more than an empty "entry" element: ...ignored... On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: > Thank you for the inputs. However, I have to disagree. My problem can be > distilled like so: > > If I create a document from an ArrayList and try to post, the > server doesn't update. > If I create a document by parsing the file made from a document that was > made from ArrayList and post, the server updates. > > This makes me think that the http output stream is not at fault, since it > works for the case for the document built from a parsed file. (I have also > since wrapped the httpOutputStream in a bufferedStreamReader and called > flush(). Still nothing). It makes me think that there is a setting which > is read from the parsed file which is not read from the ArrayList. > > So the above makes me wonder if ArrayList is a suitable list to > work with. What other container could I use? > > Regards, > Rick > > On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: > >> I agree with Jason that you should close the output stream (which will >> also flush) before getting the response code. >> >> Also, if you're going to be doing a lot of http processing I recommend >> using Apache's httpclient instead of dealing with Java's HttpConnection >> directly. >> >> >> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >> >>> When I call xmlOutputter.output(docForPosting, http.getOutputStream()), >>> this fails to update the data but I get: (Response Code: 200, Response >>> Message: OK). >>> But when I write the docForPosting to a file and then create a new >>> document from the parsed file, I can successfully update the data (Response >>> Code: 200, Response Message: OK). >>> >>> Why can I not put data successfully on the server with >>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>> >>> Your help will be appreciated. My code is below: >>> >>> >>> package myJDom; >>>> >>>> import org.jdom.*; >>>> import org.jdom.input.DOMBuilder; >>>> import org.jdom.input.SAXBuilder; >>>> import org.jdom.output.XMLOutputter; >>>> import org.xml.sax.SAXException; >>>> >>>> import java.io.File; >>>> import java.io.FileWriter; >>>> import java.io.IOException; >>>> import java.net.Authenticator; >>>> import java.net.HttpURLConnection; >>>> import java.net.URISyntaxException; >>>> import java.net.URL; >>>> import java.net.URLConnection; >>>> import java.util.ArrayList; >>>> import java.util.List; >>>> >>>> import javax.xml.parsers.DocumentBuilder; >>>> import javax.xml.parsers.DocumentBuilderFactory; >>>> import javax.xml.parsers.ParserConfigurationException; >>>> >>>> public class MyJDomParser { >>>> protected List rawElementList = new ArrayList(); >>>> protected List scrubbedElementList = new >>>> ArrayList(); >>>> protected List newElementList = new ArrayList(); >>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>> protected Document rawDoc = new Document(); >>>> protected Element element; >>>> >>>> @SuppressWarnings("unchecked") >>>> public void parseUrl() throws JDOMException, IOException { >>>> System.out.println("preparing to parse the elements..."); >>>> URL url = new URL( >>>> " >>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>> "); >>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>> rawDoc = saxBuilder.build(url); >>>> >>>> element = rawDoc.getRootElement(); >>>> rawElementList.addAll(element.getChildren()); >>>> >>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>> rawElementList.remove(0); >>>> } >>>> >>>> for (int i = 0; i < rawElementList.size(); i++) { >>>> String s = rawElementList.get(i).getText(); >>>> if (s != null && s != "") { >>>> scrubbedElementList.add(rawElementList.get(i)); >>>> } >>>> } >>>> >>>> for (Element e : scrubbedElementList) { >>>> System.out.println(e.getText()); >>>> } >>>> // for (Element e : rawElementList) { >>>> // System.out.println(e.getText()); >>>> // } >>>> } >>>> >>>> public void getAllChangedElements() throws URISyntaxException { >>>> System.out.println("preparing to change the data..."); >>>> Element entry = new Element("entry"); >>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>> newElementList.add(entry); >>>> // rawElementList.add(entry); >>>> >>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>> String s = scrubbedElementList.get(i).getText(); >>>> String name = scrubbedElementList.get(i).getName(); >>>> if (s != null && s != "") { >>>> if (name == "AccountName") { >>>> s = "****55555******"; >>>> } >>>> Element e = new Element(name); >>>> e.setText(s); >>>> newElementList.add(e); >>>> } >>>> } >>>> // return newData; >>>> // for (Element e : newElementList) { >>>> // System.out.println(e.getText()); >>>> // } >>>> } >>>> >>>> public void postData() throws IOException, JDOMException, >>>> ParserConfigurationException, SAXException { >>>> // building a document from DOM >>>> DocumentBuilderFactory dbfac = >>>> DocumentBuilderFactory.newInstance(); >>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>> org.w3c.dom.Document docPrepareToPost = >>>> docBuilder.newDocument(); >>>> >>>> // create my root element >>>> org.w3c.dom.Element root = >>>> docPrepareToPost.createElement("entry"); >>>> docPrepareToPost.appendChild(root); >>>> >>>> // add elements to my dom doc >>>> for (int i = 0; i < newElementList.size(); i++) { >>>> org.w3c.dom.Element child = docPrepareToPost >>>> .createElement(newElementList.get(i).getName()); >>>> child.setTextContent(newElementList.get(i).getText()); >>>> root.appendChild(child); >>>> } >>>> >>>> // parsing my doc from the file allows me a successful post >>>> // FileWriter fs = new FileWriter("/home/rick/deleteme/crap2"); >>>> // //posting is successful from this parsed file >>>> // xmlOutputter.output(docForPosting, fs); >>>> >>>> DocumentBuilderFactory factory = >>>> DocumentBuilderFactory.newInstance(); >>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>> new File("/home/rick/deleteme/crap2")); >>>> >>>> // setting up the stream >>>> URL url = new URL( >>>> " >>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>> "); >>>> URLConnection connection = url.openConnection(); >>>> connection.setDoOutput(true); >>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>> connection; >>>> http.setRequestMethod("PUT"); >>>> HttpURLConnection.setFollowRedirects(true); >>>> http.setRequestProperty("Content-type", >>>> "application/atom+xml;type=entry"); >>>> >>>> // creating a JDom doc from the DOM doc to facilitate streaming >>>> to the >>>> // server >>>> org.jdom.Document docForPosting = >>>> domBuilder.build(docPrepareToPost); >>>> >>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>> //this fails to update the data (Response Code: 200, Response >>>> Message: OK) >>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>> //output seems ok >>>> xmlOutputter.output(docForPosting, System.out); >>>> //the printout seems ok >>>> System.out.println("doctype = " + docForPosting.getDocType()); >>>> //=null >>>> FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); >>>> //this successfully updates the data (Response Code: 200, >>>> Response Message: OK) >>>> xmlOutputter.output(docForPosting, file); >>>> >>>> System.out.println("Response Code: " + http.getResponseCode()); >>>> System.out.println("Response Message: " + >>>> http.getResponseMessage()); >>>> } >>>> >>>> public static void main(String[] args) { >>>> MyJDomParser parser = new MyJDomParser(); >>>> Authenticator.setDefault(new MyAuthenticator()); >>>> try { >>>> parser.parseUrl(); >>>> parser.getAllChangedElements(); >>>> parser.postData(); >>>> } catch (JDOMException e) { >>>> e.printStackTrace(); >>>> } catch (IOException e) { >>>> e.printStackTrace(); >>>> } catch (URISyntaxException e) { >>>> e.printStackTrace(); >>>> } catch (ParserConfigurationException e) { >>>> e.printStackTrace(); >>>> } catch (SAXException e) { >>>> e.printStackTrace(); >>>> } >>>> } >>>> } >>>> >>> >>> *Output (snipped):* >>> >>> preparing to change the data... >>>> >>>> >>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>> >>>> >>> >>> >> >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/9af67601/attachment.htm From joe.bowbeer at gmail.com Mon Jan 19 09:11:59 2009 From: joe.bowbeer at gmail.com (Joe Bowbeer) Date: Mon Jan 19 09:12:07 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> Message-ID: <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> On Mon, Jan 19, 2009 at 9:08 AM, Joe Bowbeer wrote: > What's the diff between the two documents created in the two different > ways? > > Also, what's your root element? > > The snippet below looks like nothing more than an empty "entry" element: > > > ...ignored... Update: Nope, I got that wrong. The document itself is an "entry" and the first element is an empty "entry". Joe > > > On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: > >> Thank you for the inputs. However, I have to disagree. My problem can be >> distilled like so: >> >> If I create a document from an ArrayList and try to post, the >> server doesn't update. >> If I create a document by parsing the file made from a document that was >> made from ArrayList and post, the server updates. >> >> This makes me think that the http output stream is not at fault, since it >> works for the case for the document built from a parsed file. (I have also >> since wrapped the httpOutputStream in a bufferedStreamReader and called >> flush(). Still nothing). It makes me think that there is a setting which >> is read from the parsed file which is not read from the ArrayList. >> >> So the above makes me wonder if ArrayList is a suitable list to >> work with. What other container could I use? >> >> Regards, >> Rick >> >> On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: >> >>> I agree with Jason that you should close the output stream (which will >>> also flush) before getting the response code. >>> >>> Also, if you're going to be doing a lot of http processing I recommend >>> using Apache's httpclient instead of dealing with Java's HttpConnection >>> directly. >>> >>> >>> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >>> >>>> When I call xmlOutputter.output(docForPosting, http.getOutputStream()), >>>> this fails to update the data but I get: (Response Code: 200, Response >>>> Message: OK). >>>> But when I write the docForPosting to a file and then create a new >>>> document from the parsed file, I can successfully update the data (Response >>>> Code: 200, Response Message: OK). >>>> >>>> Why can I not put data successfully on the server with >>>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>>> >>>> Your help will be appreciated. My code is below: >>>> >>>> >>>> package myJDom; >>>>> >>>>> import org.jdom.*; >>>>> import org.jdom.input.DOMBuilder; >>>>> import org.jdom.input.SAXBuilder; >>>>> import org.jdom.output.XMLOutputter; >>>>> import org.xml.sax.SAXException; >>>>> >>>>> import java.io.File; >>>>> import java.io.FileWriter; >>>>> import java.io.IOException; >>>>> import java.net.Authenticator; >>>>> import java.net.HttpURLConnection; >>>>> import java.net.URISyntaxException; >>>>> import java.net.URL; >>>>> import java.net.URLConnection; >>>>> import java.util.ArrayList; >>>>> import java.util.List; >>>>> >>>>> import javax.xml.parsers.DocumentBuilder; >>>>> import javax.xml.parsers.DocumentBuilderFactory; >>>>> import javax.xml.parsers.ParserConfigurationException; >>>>> >>>>> public class MyJDomParser { >>>>> protected List rawElementList = new ArrayList(); >>>>> protected List scrubbedElementList = new >>>>> ArrayList(); >>>>> protected List newElementList = new ArrayList(); >>>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>>> protected Document rawDoc = new Document(); >>>>> protected Element element; >>>>> >>>>> @SuppressWarnings("unchecked") >>>>> public void parseUrl() throws JDOMException, IOException { >>>>> System.out.println("preparing to parse the elements..."); >>>>> URL url = new URL( >>>>> " >>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>> "); >>>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>>> rawDoc = saxBuilder.build(url); >>>>> >>>>> element = rawDoc.getRootElement(); >>>>> rawElementList.addAll(element.getChildren()); >>>>> >>>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>>> rawElementList.remove(0); >>>>> } >>>>> >>>>> for (int i = 0; i < rawElementList.size(); i++) { >>>>> String s = rawElementList.get(i).getText(); >>>>> if (s != null && s != "") { >>>>> scrubbedElementList.add(rawElementList.get(i)); >>>>> } >>>>> } >>>>> >>>>> for (Element e : scrubbedElementList) { >>>>> System.out.println(e.getText()); >>>>> } >>>>> // for (Element e : rawElementList) { >>>>> // System.out.println(e.getText()); >>>>> // } >>>>> } >>>>> >>>>> public void getAllChangedElements() throws URISyntaxException { >>>>> System.out.println("preparing to change the data..."); >>>>> Element entry = new Element("entry"); >>>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>>> newElementList.add(entry); >>>>> // rawElementList.add(entry); >>>>> >>>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>>> String s = scrubbedElementList.get(i).getText(); >>>>> String name = scrubbedElementList.get(i).getName(); >>>>> if (s != null && s != "") { >>>>> if (name == "AccountName") { >>>>> s = "****55555******"; >>>>> } >>>>> Element e = new Element(name); >>>>> e.setText(s); >>>>> newElementList.add(e); >>>>> } >>>>> } >>>>> // return newData; >>>>> // for (Element e : newElementList) { >>>>> // System.out.println(e.getText()); >>>>> // } >>>>> } >>>>> >>>>> public void postData() throws IOException, JDOMException, >>>>> ParserConfigurationException, SAXException { >>>>> // building a document from DOM >>>>> DocumentBuilderFactory dbfac = >>>>> DocumentBuilderFactory.newInstance(); >>>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>>> org.w3c.dom.Document docPrepareToPost = >>>>> docBuilder.newDocument(); >>>>> >>>>> // create my root element >>>>> org.w3c.dom.Element root = >>>>> docPrepareToPost.createElement("entry"); >>>>> docPrepareToPost.appendChild(root); >>>>> >>>>> // add elements to my dom doc >>>>> for (int i = 0; i < newElementList.size(); i++) { >>>>> org.w3c.dom.Element child = docPrepareToPost >>>>> .createElement(newElementList.get(i).getName()); >>>>> child.setTextContent(newElementList.get(i).getText()); >>>>> root.appendChild(child); >>>>> } >>>>> >>>>> // parsing my doc from the file allows me a successful post >>>>> // FileWriter fs = new FileWriter("/home/rick/deleteme/crap2"); >>>>> // //posting is successful from this parsed file >>>>> // xmlOutputter.output(docForPosting, fs); >>>>> >>>>> DocumentBuilderFactory factory = >>>>> DocumentBuilderFactory.newInstance(); >>>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>>> new File("/home/rick/deleteme/crap2")); >>>>> >>>>> // setting up the stream >>>>> URL url = new URL( >>>>> " >>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>> "); >>>>> URLConnection connection = url.openConnection(); >>>>> connection.setDoOutput(true); >>>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>>> connection; >>>>> http.setRequestMethod("PUT"); >>>>> HttpURLConnection.setFollowRedirects(true); >>>>> http.setRequestProperty("Content-type", >>>>> "application/atom+xml;type=entry"); >>>>> >>>>> // creating a JDom doc from the DOM doc to facilitate streaming >>>>> to the >>>>> // server >>>>> org.jdom.Document docForPosting = >>>>> domBuilder.build(docPrepareToPost); >>>>> >>>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>>> //this fails to update the data (Response Code: 200, Response >>>>> Message: OK) >>>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>>> //output seems ok >>>>> xmlOutputter.output(docForPosting, System.out); >>>>> //the printout seems ok >>>>> System.out.println("doctype = " + docForPosting.getDocType()); >>>>> //=null >>>>> FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); >>>>> //this successfully updates the data (Response Code: 200, >>>>> Response Message: OK) >>>>> xmlOutputter.output(docForPosting, file); >>>>> >>>>> System.out.println("Response Code: " + http.getResponseCode()); >>>>> System.out.println("Response Message: " + >>>>> http.getResponseMessage()); >>>>> } >>>>> >>>>> public static void main(String[] args) { >>>>> MyJDomParser parser = new MyJDomParser(); >>>>> Authenticator.setDefault(new MyAuthenticator()); >>>>> try { >>>>> parser.parseUrl(); >>>>> parser.getAllChangedElements(); >>>>> parser.postData(); >>>>> } catch (JDOMException e) { >>>>> e.printStackTrace(); >>>>> } catch (IOException e) { >>>>> e.printStackTrace(); >>>>> } catch (URISyntaxException e) { >>>>> e.printStackTrace(); >>>>> } catch (ParserConfigurationException e) { >>>>> e.printStackTrace(); >>>>> } catch (SAXException e) { >>>>> e.printStackTrace(); >>>>> } >>>>> } >>>>> } >>>>> >>>> >>>> *Output (snipped):* >>>> >>>> preparing to change the data... >>>>> >>>>> >>>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>>> >>>>> >>>> >>>> >>> >>> _______________________________________________ >>> To control your jdom-interest membership: >>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/5e175614/attachment.htm From rick.softly at gmail.com Mon Jan 19 09:45:13 2009 From: rick.softly at gmail.com (Rick Avlonitis) Date: Mon Jan 19 09:47:28 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> Message-ID: <828969970901190945t629290ocf062986a1ad42ae@mail.gmail.com> I may be wrong here, but it seems that JDom is perhaps not the choice to use when posting to an atom feed. I say this because I can output a document to a file with no problems. However, I can't out the document to an http stream. I've wrapped the stream in a buffer and called flush on it to no avail. I know that there isn't a problem with the stream, because when I create a new document from the file where I output to originally, it works. But I don't want to have to write to a file (or even a string). I want to find a solution that works. My solution is fine until I want to post the results back to the server :(. Perhaps ROME is the way to go? On Mon, Jan 19, 2009 at 7:11 PM, Joe Bowbeer wrote: > On Mon, Jan 19, 2009 at 9:08 AM, Joe Bowbeer wrote: > >> What's the diff between the two documents created in the two different >> ways? >> >> Also, what's your root element? >> >> The snippet below looks like nothing more than an empty "entry" element: >> >> >> ...ignored... > > > > > Update: Nope, I got that wrong. The document itself is an "entry" and the > first element is an empty "entry". > > Joe > > > >> >> >> On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: >> >>> Thank you for the inputs. However, I have to disagree. My problem can >>> be distilled like so: >>> >>> If I create a document from an ArrayList and try to post, the >>> server doesn't update. >>> If I create a document by parsing the file made from a document that was >>> made from ArrayList and post, the server updates. >>> >>> This makes me think that the http output stream is not at fault, since it >>> works for the case for the document built from a parsed file. (I have also >>> since wrapped the httpOutputStream in a bufferedStreamReader and called >>> flush(). Still nothing). It makes me think that there is a setting which >>> is read from the parsed file which is not read from the ArrayList. >>> >>> So the above makes me wonder if ArrayList is a suitable list to >>> work with. What other container could I use? >>> >>> Regards, >>> Rick >>> >>> On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: >>> >>>> I agree with Jason that you should close the output stream (which will >>>> also flush) before getting the response code. >>>> >>>> Also, if you're going to be doing a lot of http processing I recommend >>>> using Apache's httpclient instead of dealing with Java's HttpConnection >>>> directly. >>>> >>>> >>>> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >>>> >>>>> When I call xmlOutputter.output(docForPosting, http.getOutputStream()), >>>>> this fails to update the data but I get: (Response Code: 200, Response >>>>> Message: OK). >>>>> But when I write the docForPosting to a file and then create a new >>>>> document from the parsed file, I can successfully update the data (Response >>>>> Code: 200, Response Message: OK). >>>>> >>>>> Why can I not put data successfully on the server with >>>>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>>>> >>>>> Your help will be appreciated. My code is below: >>>>> >>>>> >>>>> package myJDom; >>>>>> >>>>>> import org.jdom.*; >>>>>> import org.jdom.input.DOMBuilder; >>>>>> import org.jdom.input.SAXBuilder; >>>>>> import org.jdom.output.XMLOutputter; >>>>>> import org.xml.sax.SAXException; >>>>>> >>>>>> import java.io.File; >>>>>> import java.io.FileWriter; >>>>>> import java.io.IOException; >>>>>> import java.net.Authenticator; >>>>>> import java.net.HttpURLConnection; >>>>>> import java.net.URISyntaxException; >>>>>> import java.net.URL; >>>>>> import java.net.URLConnection; >>>>>> import java.util.ArrayList; >>>>>> import java.util.List; >>>>>> >>>>>> import javax.xml.parsers.DocumentBuilder; >>>>>> import javax.xml.parsers.DocumentBuilderFactory; >>>>>> import javax.xml.parsers.ParserConfigurationException; >>>>>> >>>>>> public class MyJDomParser { >>>>>> protected List rawElementList = new ArrayList(); >>>>>> protected List scrubbedElementList = new >>>>>> ArrayList(); >>>>>> protected List newElementList = new ArrayList(); >>>>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>>>> protected Document rawDoc = new Document(); >>>>>> protected Element element; >>>>>> >>>>>> @SuppressWarnings("unchecked") >>>>>> public void parseUrl() throws JDOMException, IOException { >>>>>> System.out.println("preparing to parse the elements..."); >>>>>> URL url = new URL( >>>>>> " >>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>> "); >>>>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>>>> rawDoc = saxBuilder.build(url); >>>>>> >>>>>> element = rawDoc.getRootElement(); >>>>>> rawElementList.addAll(element.getChildren()); >>>>>> >>>>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>>>> rawElementList.remove(0); >>>>>> } >>>>>> >>>>>> for (int i = 0; i < rawElementList.size(); i++) { >>>>>> String s = rawElementList.get(i).getText(); >>>>>> if (s != null && s != "") { >>>>>> scrubbedElementList.add(rawElementList.get(i)); >>>>>> } >>>>>> } >>>>>> >>>>>> for (Element e : scrubbedElementList) { >>>>>> System.out.println(e.getText()); >>>>>> } >>>>>> // for (Element e : rawElementList) { >>>>>> // System.out.println(e.getText()); >>>>>> // } >>>>>> } >>>>>> >>>>>> public void getAllChangedElements() throws URISyntaxException { >>>>>> System.out.println("preparing to change the data..."); >>>>>> Element entry = new Element("entry"); >>>>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>>>> newElementList.add(entry); >>>>>> // rawElementList.add(entry); >>>>>> >>>>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>>>> String s = scrubbedElementList.get(i).getText(); >>>>>> String name = scrubbedElementList.get(i).getName(); >>>>>> if (s != null && s != "") { >>>>>> if (name == "AccountName") { >>>>>> s = "****55555******"; >>>>>> } >>>>>> Element e = new Element(name); >>>>>> e.setText(s); >>>>>> newElementList.add(e); >>>>>> } >>>>>> } >>>>>> // return newData; >>>>>> // for (Element e : newElementList) { >>>>>> // System.out.println(e.getText()); >>>>>> // } >>>>>> } >>>>>> >>>>>> public void postData() throws IOException, JDOMException, >>>>>> ParserConfigurationException, SAXException { >>>>>> // building a document from DOM >>>>>> DocumentBuilderFactory dbfac = >>>>>> DocumentBuilderFactory.newInstance(); >>>>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>>>> org.w3c.dom.Document docPrepareToPost = >>>>>> docBuilder.newDocument(); >>>>>> >>>>>> // create my root element >>>>>> org.w3c.dom.Element root = >>>>>> docPrepareToPost.createElement("entry"); >>>>>> docPrepareToPost.appendChild(root); >>>>>> >>>>>> // add elements to my dom doc >>>>>> for (int i = 0; i < newElementList.size(); i++) { >>>>>> org.w3c.dom.Element child = docPrepareToPost >>>>>> .createElement(newElementList.get(i).getName()); >>>>>> child.setTextContent(newElementList.get(i).getText()); >>>>>> root.appendChild(child); >>>>>> } >>>>>> >>>>>> // parsing my doc from the file allows me a successful post >>>>>> // FileWriter fs = new >>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>> // //posting is successful from this parsed file >>>>>> // xmlOutputter.output(docForPosting, fs); >>>>>> >>>>>> DocumentBuilderFactory factory = >>>>>> DocumentBuilderFactory.newInstance(); >>>>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>>>> new File("/home/rick/deleteme/crap2")); >>>>>> >>>>>> // setting up the stream >>>>>> URL url = new URL( >>>>>> " >>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>> "); >>>>>> URLConnection connection = url.openConnection(); >>>>>> connection.setDoOutput(true); >>>>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>>>> connection; >>>>>> http.setRequestMethod("PUT"); >>>>>> HttpURLConnection.setFollowRedirects(true); >>>>>> http.setRequestProperty("Content-type", >>>>>> "application/atom+xml;type=entry"); >>>>>> >>>>>> // creating a JDom doc from the DOM doc to facilitate >>>>>> streaming to the >>>>>> // server >>>>>> org.jdom.Document docForPosting = >>>>>> domBuilder.build(docPrepareToPost); >>>>>> >>>>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>>>> //this fails to update the data (Response Code: 200, Response >>>>>> Message: OK) >>>>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>>>> //output seems ok >>>>>> xmlOutputter.output(docForPosting, System.out); >>>>>> //the printout seems ok >>>>>> System.out.println("doctype = " + docForPosting.getDocType()); >>>>>> //=null >>>>>> FileWriter file = new FileWriter("/home/rick/deleteme/crap2"); >>>>>> >>>>>> //this successfully updates the data (Response Code: 200, >>>>>> Response Message: OK) >>>>>> xmlOutputter.output(docForPosting, file); >>>>>> >>>>>> System.out.println("Response Code: " + >>>>>> http.getResponseCode()); >>>>>> System.out.println("Response Message: " + >>>>>> http.getResponseMessage()); >>>>>> } >>>>>> >>>>>> public static void main(String[] args) { >>>>>> MyJDomParser parser = new MyJDomParser(); >>>>>> Authenticator.setDefault(new MyAuthenticator()); >>>>>> try { >>>>>> parser.parseUrl(); >>>>>> parser.getAllChangedElements(); >>>>>> parser.postData(); >>>>>> } catch (JDOMException e) { >>>>>> e.printStackTrace(); >>>>>> } catch (IOException e) { >>>>>> e.printStackTrace(); >>>>>> } catch (URISyntaxException e) { >>>>>> e.printStackTrace(); >>>>>> } catch (ParserConfigurationException e) { >>>>>> e.printStackTrace(); >>>>>> } catch (SAXException e) { >>>>>> e.printStackTrace(); >>>>>> } >>>>>> } >>>>>> } >>>>>> >>>>> >>>>> *Output (snipped):* >>>>> >>>>> preparing to change the data... >>>>>> >>>>>> >>>>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> To control your jdom-interest membership: >>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>>> >>> >>> >> > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/a520cb0a/attachment-0001.htm From joe.bowbeer at gmail.com Mon Jan 19 09:58:17 2009 From: joe.bowbeer at gmail.com (Joe Bowbeer) Date: Mon Jan 19 10:00:31 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <828969970901190945t629290ocf062986a1ad42ae@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> <828969970901190945t629290ocf062986a1ad42ae@mail.gmail.com> Message-ID: <31f2a7bd0901190958l65c61819r2a51d970c8ef2c09@mail.gmail.com> What you're putting doesn't like like a valid atom post. The root should be a *feed* instead of an *entry*, right? And that empty *entry* in the first element doesn't look right. See sample feed here: http://www.ibm.com/developerworks/library/x-tipatom2/ Yes, I'd recommend using ROME, which itself uses JDOM. Joe On Mon, Jan 19, 2009 at 9:45 AM, Rick Avlonitis wrote: > I may be wrong here, but it seems that JDom is perhaps not the choice to > use when posting to an atom feed. I say this because I can output a > document to a file with no problems. However, I can't out the document to > an http stream. I've wrapped the stream in a buffer and called flush on it > to no avail. I know that there isn't a problem with the stream, because > when I create a new document from the file where I output to originally, it > works. But I don't want to have to write to a file (or even a string). I > want to find a solution that works. My solution is fine until I want to > post the results back to the server :(. Perhaps ROME is the way to go? > > > On Mon, Jan 19, 2009 at 7:11 PM, Joe Bowbeer wrote: > >> On Mon, Jan 19, 2009 at 9:08 AM, Joe Bowbeer wrote: >> >>> What's the diff between the two documents created in the two different >>> ways? >>> >>> Also, what's your root element? >>> >>> The snippet below looks like nothing more than an empty "entry" element: >>> >>> >>> ...ignored... >> >> >> >> >> Update: Nope, I got that wrong. The document itself is an "entry" and the >> first element is an empty "entry". >> >> Joe >> >> >> >>> >>> >>> On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: >>> >>>> Thank you for the inputs. However, I have to disagree. My problem can >>>> be distilled like so: >>>> >>>> If I create a document from an ArrayList and try to post, the >>>> server doesn't update. >>>> If I create a document by parsing the file made from a document that was >>>> made from ArrayList and post, the server updates. >>>> >>>> This makes me think that the http output stream is not at fault, since >>>> it works for the case for the document built from a parsed file. (I have >>>> also since wrapped the httpOutputStream in a bufferedStreamReader and called >>>> flush(). Still nothing). It makes me think that there is a setting which >>>> is read from the parsed file which is not read from the ArrayList. >>>> >>>> So the above makes me wonder if ArrayList is a suitable list to >>>> work with. What other container could I use? >>>> >>>> Regards, >>>> Rick >>>> >>>> On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: >>>> >>>>> I agree with Jason that you should close the output stream (which will >>>>> also flush) before getting the response code. >>>>> >>>>> Also, if you're going to be doing a lot of http processing I recommend >>>>> using Apache's httpclient instead of dealing with Java's HttpConnection >>>>> directly. >>>>> >>>>> >>>>> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >>>>> >>>>>> When I call xmlOutputter.output(docForPosting, >>>>>> http.getOutputStream()), this fails to update the data but I get: (Response >>>>>> Code: 200, Response Message: OK). >>>>>> But when I write the docForPosting to a file and then create a new >>>>>> document from the parsed file, I can successfully update the data (Response >>>>>> Code: 200, Response Message: OK). >>>>>> >>>>>> Why can I not put data successfully on the server with >>>>>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>>>>> >>>>>> Your help will be appreciated. My code is below: >>>>>> >>>>>> >>>>>> package myJDom; >>>>>>> >>>>>>> import org.jdom.*; >>>>>>> import org.jdom.input.DOMBuilder; >>>>>>> import org.jdom.input.SAXBuilder; >>>>>>> import org.jdom.output.XMLOutputter; >>>>>>> import org.xml.sax.SAXException; >>>>>>> >>>>>>> import java.io.File; >>>>>>> import java.io.FileWriter; >>>>>>> import java.io.IOException; >>>>>>> import java.net.Authenticator; >>>>>>> import java.net.HttpURLConnection; >>>>>>> import java.net.URISyntaxException; >>>>>>> import java.net.URL; >>>>>>> import java.net.URLConnection; >>>>>>> import java.util.ArrayList; >>>>>>> import java.util.List; >>>>>>> >>>>>>> import javax.xml.parsers.DocumentBuilder; >>>>>>> import javax.xml.parsers.DocumentBuilderFactory; >>>>>>> import javax.xml.parsers.ParserConfigurationException; >>>>>>> >>>>>>> public class MyJDomParser { >>>>>>> protected List rawElementList = new >>>>>>> ArrayList(); >>>>>>> protected List scrubbedElementList = new >>>>>>> ArrayList(); >>>>>>> protected List newElementList = new >>>>>>> ArrayList(); >>>>>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>>>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>>>>> protected Document rawDoc = new Document(); >>>>>>> protected Element element; >>>>>>> >>>>>>> @SuppressWarnings("unchecked") >>>>>>> public void parseUrl() throws JDOMException, IOException { >>>>>>> System.out.println("preparing to parse the elements..."); >>>>>>> URL url = new URL( >>>>>>> " >>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>> "); >>>>>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>>>>> rawDoc = saxBuilder.build(url); >>>>>>> >>>>>>> element = rawDoc.getRootElement(); >>>>>>> rawElementList.addAll(element.getChildren()); >>>>>>> >>>>>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>>>>> rawElementList.remove(0); >>>>>>> } >>>>>>> >>>>>>> for (int i = 0; i < rawElementList.size(); i++) { >>>>>>> String s = rawElementList.get(i).getText(); >>>>>>> if (s != null && s != "") { >>>>>>> scrubbedElementList.add(rawElementList.get(i)); >>>>>>> } >>>>>>> } >>>>>>> >>>>>>> for (Element e : scrubbedElementList) { >>>>>>> System.out.println(e.getText()); >>>>>>> } >>>>>>> // for (Element e : rawElementList) { >>>>>>> // System.out.println(e.getText()); >>>>>>> // } >>>>>>> } >>>>>>> >>>>>>> public void getAllChangedElements() throws URISyntaxException { >>>>>>> System.out.println("preparing to change the data..."); >>>>>>> Element entry = new Element("entry"); >>>>>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>>>>> newElementList.add(entry); >>>>>>> // rawElementList.add(entry); >>>>>>> >>>>>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>>>>> String s = scrubbedElementList.get(i).getText(); >>>>>>> String name = scrubbedElementList.get(i).getName(); >>>>>>> if (s != null && s != "") { >>>>>>> if (name == "AccountName") { >>>>>>> s = "****55555******"; >>>>>>> } >>>>>>> Element e = new Element(name); >>>>>>> e.setText(s); >>>>>>> newElementList.add(e); >>>>>>> } >>>>>>> } >>>>>>> // return newData; >>>>>>> // for (Element e : newElementList) { >>>>>>> // System.out.println(e.getText()); >>>>>>> // } >>>>>>> } >>>>>>> >>>>>>> public void postData() throws IOException, JDOMException, >>>>>>> ParserConfigurationException, SAXException { >>>>>>> // building a document from DOM >>>>>>> DocumentBuilderFactory dbfac = >>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>>>>> org.w3c.dom.Document docPrepareToPost = >>>>>>> docBuilder.newDocument(); >>>>>>> >>>>>>> // create my root element >>>>>>> org.w3c.dom.Element root = >>>>>>> docPrepareToPost.createElement("entry"); >>>>>>> docPrepareToPost.appendChild(root); >>>>>>> >>>>>>> // add elements to my dom doc >>>>>>> for (int i = 0; i < newElementList.size(); i++) { >>>>>>> org.w3c.dom.Element child = docPrepareToPost >>>>>>> .createElement(newElementList.get(i).getName()); >>>>>>> child.setTextContent(newElementList.get(i).getText()); >>>>>>> root.appendChild(child); >>>>>>> } >>>>>>> >>>>>>> // parsing my doc from the file allows me a successful post >>>>>>> // FileWriter fs = new >>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>> // //posting is successful from this parsed file >>>>>>> // xmlOutputter.output(docForPosting, fs); >>>>>>> >>>>>>> DocumentBuilderFactory factory = >>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>>>>> new File("/home/rick/deleteme/crap2")); >>>>>>> >>>>>>> // setting up the stream >>>>>>> URL url = new URL( >>>>>>> " >>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>> "); >>>>>>> URLConnection connection = url.openConnection(); >>>>>>> connection.setDoOutput(true); >>>>>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>>>>> connection; >>>>>>> http.setRequestMethod("PUT"); >>>>>>> HttpURLConnection.setFollowRedirects(true); >>>>>>> http.setRequestProperty("Content-type", >>>>>>> "application/atom+xml;type=entry"); >>>>>>> >>>>>>> // creating a JDom doc from the DOM doc to facilitate >>>>>>> streaming to the >>>>>>> // server >>>>>>> org.jdom.Document docForPosting = >>>>>>> domBuilder.build(docPrepareToPost); >>>>>>> >>>>>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>>>>> //this fails to update the data (Response Code: 200, Response >>>>>>> Message: OK) >>>>>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>>>>> //output seems ok >>>>>>> xmlOutputter.output(docForPosting, System.out); >>>>>>> //the printout seems ok >>>>>>> System.out.println("doctype = " + >>>>>>> docForPosting.getDocType()); //=null >>>>>>> FileWriter file = new >>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>> //this successfully updates the data (Response Code: 200, >>>>>>> Response Message: OK) >>>>>>> xmlOutputter.output(docForPosting, file); >>>>>>> >>>>>>> System.out.println("Response Code: " + >>>>>>> http.getResponseCode()); >>>>>>> System.out.println("Response Message: " + >>>>>>> http.getResponseMessage()); >>>>>>> } >>>>>>> >>>>>>> public static void main(String[] args) { >>>>>>> MyJDomParser parser = new MyJDomParser(); >>>>>>> Authenticator.setDefault(new MyAuthenticator()); >>>>>>> try { >>>>>>> parser.parseUrl(); >>>>>>> parser.getAllChangedElements(); >>>>>>> parser.postData(); >>>>>>> } catch (JDOMException e) { >>>>>>> e.printStackTrace(); >>>>>>> } catch (IOException e) { >>>>>>> e.printStackTrace(); >>>>>>> } catch (URISyntaxException e) { >>>>>>> e.printStackTrace(); >>>>>>> } catch (ParserConfigurationException e) { >>>>>>> e.printStackTrace(); >>>>>>> } catch (SAXException e) { >>>>>>> e.printStackTrace(); >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> >>>>>> >>>>>> *Output (snipped):* >>>>>> >>>>>> preparing to change the data... >>>>>>> >>>>>>> >>>>>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>>>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>>>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> To control your jdom-interest membership: >>>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>>>> >>>> >>>> >>> >> >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/42708ddc/attachment.htm From rick.softly at gmail.com Mon Jan 19 10:27:48 2009 From: rick.softly at gmail.com (Rick Avlonitis) Date: Mon Jan 19 10:30:21 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <31f2a7bd0901190958l65c61819r2a51d970c8ef2c09@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> <828969970901190945t629290ocf062986a1ad42ae@mail.gmail.com> <31f2a7bd0901190958l65c61819r2a51d970c8ef2c09@mail.gmail.com> Message-ID: <828969970901191027vb323650w9a7252812f19a5a6@mail.gmail.com> Thank you for the link (although it's in php). That root *entry* I got from some C# example. I'm trying to implement a form of ReSTful webservice, where I call a URI (discovery will be through ROME, I suspect) and parse the xml with jdom (at least it does that well ;). In order to change the text values of the elements, I will have to iterate through them (jdom). Then I put them back together in a document and PUT them back on the server. That was the theory :( You are right in noticing the empty first element - that slipped past my eye. Although I did get this damnable code PUTting to the server with a document parsed from a file (the file being the result of a jdom document output). That there made me think the jdom api was fishy ;) I'll try ROME and report back. On Mon, Jan 19, 2009 at 7:58 PM, Joe Bowbeer wrote: > What you're putting doesn't like like a valid atom post. > > The root should be a *feed* instead of an *entry*, right? > > And that empty *entry* in the first element doesn't look right. > > See sample feed here: > > http://www.ibm.com/developerworks/library/x-tipatom2/ > > Yes, I'd recommend using ROME, which itself uses JDOM. > > Joe > > On Mon, Jan 19, 2009 at 9:45 AM, Rick Avlonitis wrote: > >> I may be wrong here, but it seems that JDom is perhaps not the choice to >> use when posting to an atom feed. I say this because I can output a >> document to a file with no problems. However, I can't out the document to >> an http stream. I've wrapped the stream in a buffer and called flush on it >> to no avail. I know that there isn't a problem with the stream, because >> when I create a new document from the file where I output to originally, it >> works. But I don't want to have to write to a file (or even a string). I >> want to find a solution that works. My solution is fine until I want to >> post the results back to the server :(. Perhaps ROME is the way to go? >> >> >> On Mon, Jan 19, 2009 at 7:11 PM, Joe Bowbeer wrote: >> >>> On Mon, Jan 19, 2009 at 9:08 AM, Joe Bowbeer wrote: >>> >>>> What's the diff between the two documents created in the two different >>>> ways? >>>> >>>> Also, what's your root element? >>>> >>>> The snippet below looks like nothing more than an empty "entry" element: >>>> >>>> >>>> ...ignored... >>> >>> >>> >>> >>> Update: Nope, I got that wrong. The document itself is an "entry" and >>> the first element is an empty "entry". >>> >>> Joe >>> >>> >>> >>>> >>>> >>>> On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: >>>> >>>>> Thank you for the inputs. However, I have to disagree. My problem can >>>>> be distilled like so: >>>>> >>>>> If I create a document from an ArrayList and try to post, the >>>>> server doesn't update. >>>>> If I create a document by parsing the file made from a document that >>>>> was made from ArrayList and post, the server updates. >>>>> >>>>> This makes me think that the http output stream is not at fault, since >>>>> it works for the case for the document built from a parsed file. (I have >>>>> also since wrapped the httpOutputStream in a bufferedStreamReader and called >>>>> flush(). Still nothing). It makes me think that there is a setting which >>>>> is read from the parsed file which is not read from the ArrayList. >>>>> >>>>> So the above makes me wonder if ArrayList is a suitable list >>>>> to work with. What other container could I use? >>>>> >>>>> Regards, >>>>> Rick >>>>> >>>>> On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: >>>>> >>>>>> I agree with Jason that you should close the output stream (which >>>>>> will also flush) before getting the response code. >>>>>> >>>>>> Also, if you're going to be doing a lot of http processing I recommend >>>>>> using Apache's httpclient instead of dealing with Java's HttpConnection >>>>>> directly. >>>>>> >>>>>> >>>>>> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >>>>>> >>>>>>> When I call xmlOutputter.output(docForPosting, >>>>>>> http.getOutputStream()), this fails to update the data but I get: (Response >>>>>>> Code: 200, Response Message: OK). >>>>>>> But when I write the docForPosting to a file and then create a new >>>>>>> document from the parsed file, I can successfully update the data (Response >>>>>>> Code: 200, Response Message: OK). >>>>>>> >>>>>>> Why can I not put data successfully on the server with >>>>>>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>>>>>> >>>>>>> Your help will be appreciated. My code is below: >>>>>>> >>>>>>> >>>>>>> package myJDom; >>>>>>>> >>>>>>>> import org.jdom.*; >>>>>>>> import org.jdom.input.DOMBuilder; >>>>>>>> import org.jdom.input.SAXBuilder; >>>>>>>> import org.jdom.output.XMLOutputter; >>>>>>>> import org.xml.sax.SAXException; >>>>>>>> >>>>>>>> import java.io.File; >>>>>>>> import java.io.FileWriter; >>>>>>>> import java.io.IOException; >>>>>>>> import java.net.Authenticator; >>>>>>>> import java.net.HttpURLConnection; >>>>>>>> import java.net.URISyntaxException; >>>>>>>> import java.net.URL; >>>>>>>> import java.net.URLConnection; >>>>>>>> import java.util.ArrayList; >>>>>>>> import java.util.List; >>>>>>>> >>>>>>>> import javax.xml.parsers.DocumentBuilder; >>>>>>>> import javax.xml.parsers.DocumentBuilderFactory; >>>>>>>> import javax.xml.parsers.ParserConfigurationException; >>>>>>>> >>>>>>>> public class MyJDomParser { >>>>>>>> protected List rawElementList = new >>>>>>>> ArrayList(); >>>>>>>> protected List scrubbedElementList = new >>>>>>>> ArrayList(); >>>>>>>> protected List newElementList = new >>>>>>>> ArrayList(); >>>>>>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>>>>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>>>>>> protected Document rawDoc = new Document(); >>>>>>>> protected Element element; >>>>>>>> >>>>>>>> @SuppressWarnings("unchecked") >>>>>>>> public void parseUrl() throws JDOMException, IOException { >>>>>>>> System.out.println("preparing to parse the elements..."); >>>>>>>> URL url = new URL( >>>>>>>> " >>>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>>> "); >>>>>>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>>>>>> rawDoc = saxBuilder.build(url); >>>>>>>> >>>>>>>> element = rawDoc.getRootElement(); >>>>>>>> rawElementList.addAll(element.getChildren()); >>>>>>>> >>>>>>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>>>>>> rawElementList.remove(0); >>>>>>>> } >>>>>>>> >>>>>>>> for (int i = 0; i < rawElementList.size(); i++) { >>>>>>>> String s = rawElementList.get(i).getText(); >>>>>>>> if (s != null && s != "") { >>>>>>>> scrubbedElementList.add(rawElementList.get(i)); >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> for (Element e : scrubbedElementList) { >>>>>>>> System.out.println(e.getText()); >>>>>>>> } >>>>>>>> // for (Element e : rawElementList) { >>>>>>>> // System.out.println(e.getText()); >>>>>>>> // } >>>>>>>> } >>>>>>>> >>>>>>>> public void getAllChangedElements() throws URISyntaxException { >>>>>>>> System.out.println("preparing to change the data..."); >>>>>>>> Element entry = new Element("entry"); >>>>>>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>>>>>> newElementList.add(entry); >>>>>>>> // rawElementList.add(entry); >>>>>>>> >>>>>>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>>>>>> String s = scrubbedElementList.get(i).getText(); >>>>>>>> String name = scrubbedElementList.get(i).getName(); >>>>>>>> if (s != null && s != "") { >>>>>>>> if (name == "AccountName") { >>>>>>>> s = "****55555******"; >>>>>>>> } >>>>>>>> Element e = new Element(name); >>>>>>>> e.setText(s); >>>>>>>> newElementList.add(e); >>>>>>>> } >>>>>>>> } >>>>>>>> // return newData; >>>>>>>> // for (Element e : newElementList) { >>>>>>>> // System.out.println(e.getText()); >>>>>>>> // } >>>>>>>> } >>>>>>>> >>>>>>>> public void postData() throws IOException, JDOMException, >>>>>>>> ParserConfigurationException, SAXException { >>>>>>>> // building a document from DOM >>>>>>>> DocumentBuilderFactory dbfac = >>>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>>>>>> org.w3c.dom.Document docPrepareToPost = >>>>>>>> docBuilder.newDocument(); >>>>>>>> >>>>>>>> // create my root element >>>>>>>> org.w3c.dom.Element root = >>>>>>>> docPrepareToPost.createElement("entry"); >>>>>>>> docPrepareToPost.appendChild(root); >>>>>>>> >>>>>>>> // add elements to my dom doc >>>>>>>> for (int i = 0; i < newElementList.size(); i++) { >>>>>>>> org.w3c.dom.Element child = docPrepareToPost >>>>>>>> .createElement(newElementList.get(i).getName()); >>>>>>>> child.setTextContent(newElementList.get(i).getText()); >>>>>>>> root.appendChild(child); >>>>>>>> } >>>>>>>> >>>>>>>> // parsing my doc from the file allows me a successful post >>>>>>>> // FileWriter fs = new >>>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>>> // //posting is successful from this parsed file >>>>>>>> // xmlOutputter.output(docForPosting, fs); >>>>>>>> >>>>>>>> DocumentBuilderFactory factory = >>>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>>>>>> new File("/home/rick/deleteme/crap2")); >>>>>>>> >>>>>>>> // setting up the stream >>>>>>>> URL url = new URL( >>>>>>>> " >>>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>>> "); >>>>>>>> URLConnection connection = url.openConnection(); >>>>>>>> connection.setDoOutput(true); >>>>>>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>>>>>> connection; >>>>>>>> http.setRequestMethod("PUT"); >>>>>>>> HttpURLConnection.setFollowRedirects(true); >>>>>>>> http.setRequestProperty("Content-type", >>>>>>>> "application/atom+xml;type=entry"); >>>>>>>> >>>>>>>> // creating a JDom doc from the DOM doc to facilitate >>>>>>>> streaming to the >>>>>>>> // server >>>>>>>> org.jdom.Document docForPosting = >>>>>>>> domBuilder.build(docPrepareToPost); >>>>>>>> >>>>>>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>>>>>> //this fails to update the data (Response Code: 200, >>>>>>>> Response Message: OK) >>>>>>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>>>>>> //output seems ok >>>>>>>> xmlOutputter.output(docForPosting, System.out); >>>>>>>> //the printout seems ok >>>>>>>> System.out.println("doctype = " + >>>>>>>> docForPosting.getDocType()); //=null >>>>>>>> FileWriter file = new >>>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>>> //this successfully updates the data (Response Code: 200, >>>>>>>> Response Message: OK) >>>>>>>> xmlOutputter.output(docForPosting, file); >>>>>>>> >>>>>>>> System.out.println("Response Code: " + >>>>>>>> http.getResponseCode()); >>>>>>>> System.out.println("Response Message: " + >>>>>>>> http.getResponseMessage()); >>>>>>>> } >>>>>>>> >>>>>>>> public static void main(String[] args) { >>>>>>>> MyJDomParser parser = new MyJDomParser(); >>>>>>>> Authenticator.setDefault(new MyAuthenticator()); >>>>>>>> try { >>>>>>>> parser.parseUrl(); >>>>>>>> parser.getAllChangedElements(); >>>>>>>> parser.postData(); >>>>>>>> } catch (JDOMException e) { >>>>>>>> e.printStackTrace(); >>>>>>>> } catch (IOException e) { >>>>>>>> e.printStackTrace(); >>>>>>>> } catch (URISyntaxException e) { >>>>>>>> e.printStackTrace(); >>>>>>>> } catch (ParserConfigurationException e) { >>>>>>>> e.printStackTrace(); >>>>>>>> } catch (SAXException e) { >>>>>>>> e.printStackTrace(); >>>>>>>> } >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>> >>>>>>> *Output (snipped):* >>>>>>> >>>>>>> preparing to change the data... >>>>>>>> >>>>>>>> >>>>>>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>>>>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>>>>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> To control your jdom-interest membership: >>>>>> >>>>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>>>>> >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> To control your jdom-interest membership: >>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>> >> >> > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090119/1e7808cb/attachment.htm From sam_north at nfumutual.co.uk Thu Jan 22 00:41:27 2009 From: sam_north at nfumutual.co.uk (oxymoron) Date: Thu Jan 22 00:41:37 2009 Subject: [jdom-interest] JDOM WebSphere and the dreaded classpath Message-ID: <21589217.post@talk.nabble.com> Hi folks, I would like to use JDOM in a plugin I'm writing for a websphere application. We're using WebSphere 6.0.2.7 and the application running on top of it is called xPression. xPression (a print/reporting server) can have user exits (basically a plugin) written in java a class which can be dynamically be loaded and used by the application. I have written a user exit class that loads up an xml document in JDOM and then uses XPath to return specific bits of data from the xml. This is all works on the local machine in NetBeans with the jdom and necessary jars added to the project library. When running on the server, I run into the problem where it cannot load the default SAXParser as it doesn't implement XMLParser. It appears that in my WebSphere classpath another (older) SAXParser is present. I have confirmed this by using a bit of code I found on the web which returns the url for a class - in this case, SAXParser is being loaded from the \java\jre\lib\xml.jar somewhere under the websphere home directory and not from the later version I placed on the server. I've added the jdom and its necessary lib jars to the end of websphere class path - I don't want to contaminate the server with newer versions of code as this will probably break xpression. So... my question is around jars and manifest class path. What I am hoping is that I can add a manifest class path to the jdom jar which will override the websphere class path, therefore loading the correct version of SAXPath and other required jdom libs. This seems to be possible for jar apps but I'm not sure about class libraries in websphere? Or perhaps someone can suggest another way I can override the WS classpath just for jdom? In fact, can anyone suggest a way of being able to use XPath on my WS version without using an external java lib at all? Any help would be appreciated. Cheers Sam -- View this message in context: http://www.nabble.com/JDOM-WebSphere-and-the-dreaded-classpath-tp21589217p21589217.html Sent from the JDOM - General mailing list archive at Nabble.com. From sean at seansullivan.com Thu Jan 22 01:12:50 2009 From: sean at seansullivan.com (Sean Sullivan) Date: Thu Jan 22 01:13:08 2009 Subject: [jdom-interest] JDOM WebSphere and the dreaded classpath In-Reply-To: <21589217.post@talk.nabble.com> References: <21589217.post@talk.nabble.com> Message-ID: <3a0630af0901220112g29556f6fl67e0bbf21861b218@mail.gmail.com> I was able to use jdom.jar in a web application in Websphere 6.0 @see http://www.jdom.org/pipermail/jdom-interest/2005-May/014856.html Sean On Thu, Jan 22, 2009 at 9:41 AM, oxymoron wrote: > > Hi folks, I would like to use JDOM in a plugin I'm writing for a websphere > application. We're using WebSphere 6.0.2.7 and the application running on > top of it is called xPression. xPression (a print/reporting server) can have > user exits (basically a plugin) written in java a class which can be > dynamically be loaded and used by the application. > > I have written a user exit class that loads up an xml document in JDOM and > then uses XPath to return specific bits of data from the xml. This is all > works on the local machine in NetBeans with the jdom and necessary jars > added to the project library. > > When running on the server, I run into the problem where it cannot load the > default SAXParser as it doesn't implement XMLParser. It appears that in my > WebSphere classpath another (older) SAXParser is present. I have confirmed > this by using a bit of code I found on the web which returns the url for a > class - in this case, SAXParser is being loaded from the > \java\jre\lib\xml.jar somewhere under the websphere home directory and not > from the later version I placed on the server. I've added the jdom and its > necessary lib jars to the end of websphere class path - I don't want to > contaminate the server with newer versions of code as this will probably > break xpression. > > So... my question is around jars and manifest class path. What I am hoping > is that I can add a manifest class path to the jdom jar which will override > the websphere class path, therefore loading the correct version of SAXPath > and other required jdom libs. This seems to be possible for jar apps but I'm > not sure about class libraries in websphere? > > Or perhaps someone can suggest another way I can override the WS classpath > just for jdom? > > In fact, can anyone suggest a way of being able to use XPath on my WS > version without using an external java lib at all? Any help would be > appreciated. > > Cheers > > Sam > -- > View this message in context: http://www.nabble.com/JDOM-WebSphere-and-the-dreaded-classpath-tp21589217p21589217.html > Sent from the JDOM - General mailing list archive at Nabble.com. > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com > From sam_north at nfumutual.co.uk Thu Jan 22 02:33:30 2009 From: sam_north at nfumutual.co.uk (oxymoron) Date: Thu Jan 22 02:33:41 2009 Subject: [jdom-interest] JDOM WebSphere and the dreaded classpath In-Reply-To: <3a0630af0901220112g29556f6fl67e0bbf21861b218@mail.gmail.com> References: <21589217.post@talk.nabble.com> <3a0630af0901220112g29556f6fl67e0bbf21861b218@mail.gmail.com> Message-ID: <21601589.post@talk.nabble.com> Unfortunately I can't take the existing IBM JDom out of the classpath as it is being used by the xPression application and I can't run the risk of breaking it. I would just use IBM's JDOM but the version supplied does not support XPath. What I require is a way of overriding the classpath just for my user exit code... Sean Sullivan-3 wrote: > > I was able to use jdom.jar in a web application in Websphere 6.0 > > @see http://www.jdom.org/pipermail/jdom-interest/2005-May/014856.html > > Sean > > On Thu, Jan 22, 2009 at 9:41 AM, oxymoron > wrote: >> >> Hi folks, I would like to use JDOM in a plugin I'm writing for a >> websphere >> application. We're using WebSphere 6.0.2.7 and the application running on >> top of it is called xPression. xPression (a print/reporting server) can >> have >> user exits (basically a plugin) written in java a class which can be >> dynamically be loaded and used by the application. >> >> I have written a user exit class that loads up an xml document in JDOM >> and >> then uses XPath to return specific bits of data from the xml. This is all >> works on the local machine in NetBeans with the jdom and necessary jars >> added to the project library. >> >> When running on the server, I run into the problem where it cannot load >> the >> default SAXParser as it doesn't implement XMLParser. It appears that in >> my >> WebSphere classpath another (older) SAXParser is present. I have >> confirmed >> this by using a bit of code I found on the web which returns the url for >> a >> class - in this case, SAXParser is being loaded from the >> \java\jre\lib\xml.jar somewhere under the websphere home directory and >> not >> from the later version I placed on the server. I've added the jdom and >> its >> necessary lib jars to the end of websphere class path - I don't want to >> contaminate the server with newer versions of code as this will probably >> break xpression. >> >> So... my question is around jars and manifest class path. What I am >> hoping >> is that I can add a manifest class path to the jdom jar which will >> override >> the websphere class path, therefore loading the correct version of >> SAXPath >> and other required jdom libs. This seems to be possible for jar apps but >> I'm >> not sure about class libraries in websphere? >> >> Or perhaps someone can suggest another way I can override the WS >> classpath >> just for jdom? >> >> In fact, can anyone suggest a way of being able to use XPath on my WS >> version without using an external java lib at all? Any help would be >> appreciated. >> >> Cheers >> >> Sam >> -- >> View this message in context: >> http://www.nabble.com/JDOM-WebSphere-and-the-dreaded-classpath-tp21589217p21589217.html >> Sent from the JDOM - General mailing list archive at Nabble.com. >> >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >> > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com > > -- View this message in context: http://www.nabble.com/JDOM-WebSphere-and-the-dreaded-classpath-tp21589217p21601589.html Sent from the JDOM - General mailing list archive at Nabble.com. From ondra at cifka.com Sun Jan 25 15:21:56 2009 From: ondra at cifka.com (ondra.cifka) Date: Sun Jan 25 15:22:05 2009 Subject: [jdom-interest] Validating a JDOMSource with line numbers? Message-ID: <21639302.post@talk.nabble.com> Hello, I validate a JDOMSource using a schema-based Validator and display validation errors using an ErrorHandler. But the getSystemId() of the SAXParseException returns null and getLineNumber() returns -1. How can I get systemId and lineNumber for the errors? Thanks Ondra -- View this message in context: http://www.nabble.com/Validating-a-JDOMSource-with-line-numbers--tp21639302p21639302.html Sent from the JDOM - General mailing list archive at Nabble.com. From rick.softly at gmail.com Tue Jan 27 03:00:26 2009 From: rick.softly at gmail.com (Rick) Date: Tue Jan 27 03:00:41 2009 Subject: [jdom-interest] xmlOutputter question In-Reply-To: <828969970901191027vb323650w9a7252812f19a5a6@mail.gmail.com> References: <828969970901160526s48d77137x75eda63fe54314cc@mail.gmail.com> <31f2a7bd0901161549y556af547rb4e1771f864b5cea@mail.gmail.com> <828969970901190115wc0a44edg88be0a2db2b207e4@mail.gmail.com> <31f2a7bd0901190908h4728ffefrc2dccca07af55fca@mail.gmail.com> <31f2a7bd0901190911n5bf1abcewde39bfb093d4df91@mail.gmail.com> <828969970901190945t629290ocf062986a1ad42ae@mail.gmail.com> <31f2a7bd0901190958l65c61819r2a51d970c8ef2c09@mail.gmail.com> <828969970901191027vb323650w9a7252812f19a5a6@mail.gmail.com> Message-ID: <828969970901270300o2a800c55k5a29f6e1683b47cd@mail.gmail.com> Ok, the problem is solved. It seems that the app on the server is acting in a non-standard way. Even though it apparently supports atom and rss, I couldn't post to it successfully using jdom or RoME. My only hope lay in constructing the correct string and parsing it with jdom to post to the server. It worked after I reverse engineered the string. A tip for those going down this path is to strip the prologue from the xml string before parsing it with a SAXBuilder. The SAXBuilder will add the correct prologue before posting. On Mon, Jan 19, 2009 at 8:27 PM, Rick Avlonitis wrote: > Thank you for the link (although it's in php). That root *entry* I got > from some C# example. I'm trying to implement a form of ReSTful webservice, > where I call a URI (discovery will be through ROME, I suspect) and parse the > xml with jdom (at least it does that well ;). In order to change the text > values of the elements, I will have to iterate through them (jdom). Then I > put them back together in a document and PUT them back on the server. That > was the theory :( > > You are right in noticing the empty first element - that slipped past my > eye. Although I did get this damnable code PUTting to the server with a > document parsed from a file (the file being the result of a jdom document > output). That there made me think the jdom api was fishy ;) I'll try ROME > and report back. > > > On Mon, Jan 19, 2009 at 7:58 PM, Joe Bowbeer wrote: > >> What you're putting doesn't like like a valid atom post. >> >> The root should be a *feed* instead of an *entry*, right? >> >> And that empty *entry* in the first element doesn't look right. >> >> See sample feed here: >> >> http://www.ibm.com/developerworks/library/x-tipatom2/ >> >> Yes, I'd recommend using ROME, which itself uses JDOM. >> >> Joe >> >> On Mon, Jan 19, 2009 at 9:45 AM, Rick Avlonitis wrote: >> >>> I may be wrong here, but it seems that JDom is perhaps not the choice to >>> use when posting to an atom feed. I say this because I can output a >>> document to a file with no problems. However, I can't out the document to >>> an http stream. I've wrapped the stream in a buffer and called flush on it >>> to no avail. I know that there isn't a problem with the stream, because >>> when I create a new document from the file where I output to originally, it >>> works. But I don't want to have to write to a file (or even a string). I >>> want to find a solution that works. My solution is fine until I want to >>> post the results back to the server :(. Perhaps ROME is the way to go? >>> >>> >>> On Mon, Jan 19, 2009 at 7:11 PM, Joe Bowbeer wrote: >>> >>>> On Mon, Jan 19, 2009 at 9:08 AM, Joe Bowbeer wrote: >>>> >>>>> What's the diff between the two documents created in the two different >>>>> ways? >>>>> >>>>> Also, what's your root element? >>>>> >>>>> The snippet below looks like nothing more than an empty "entry" >>>>> element: >>>>> >>>>> >>>>> ...ignored... >>>> >>>> >>>> >>>> >>>> Update: Nope, I got that wrong. The document itself is an "entry" and >>>> the first element is an empty "entry". >>>> >>>> Joe >>>> >>>> >>>> >>>>> >>>>> >>>>> On Mon, Jan 19, 2009 at 1:15 AM, Rick Avlonitis wrote: >>>>> >>>>>> Thank you for the inputs. However, I have to disagree. My problem >>>>>> can be distilled like so: >>>>>> >>>>>> If I create a document from an ArrayList and try to post, the >>>>>> server doesn't update. >>>>>> If I create a document by parsing the file made from a document that >>>>>> was made from ArrayList and post, the server updates. >>>>>> >>>>>> This makes me think that the http output stream is not at fault, since >>>>>> it works for the case for the document built from a parsed file. (I have >>>>>> also since wrapped the httpOutputStream in a bufferedStreamReader and called >>>>>> flush(). Still nothing). It makes me think that there is a setting which >>>>>> is read from the parsed file which is not read from the ArrayList. >>>>>> >>>>>> So the above makes me wonder if ArrayList is a suitable list >>>>>> to work with. What other container could I use? >>>>>> >>>>>> Regards, >>>>>> Rick >>>>>> >>>>>> On Sat, Jan 17, 2009 at 1:49 AM, Joe Bowbeer wrote: >>>>>> >>>>>>> I agree with Jason that you should close the output stream (which >>>>>>> will also flush) before getting the response code. >>>>>>> >>>>>>> Also, if you're going to be doing a lot of http processing I >>>>>>> recommend using Apache's httpclient instead of dealing with Java's >>>>>>> HttpConnection directly. >>>>>>> >>>>>>> >>>>>>> On Fri, Jan 16, 2009 at 5:26 AM, Rick Avlonitis wrote: >>>>>>> >>>>>>>> When I call xmlOutputter.output(docForPosting, >>>>>>>> http.getOutputStream()), this fails to update the data but I get: (Response >>>>>>>> Code: 200, Response Message: OK). >>>>>>>> But when I write the docForPosting to a file and then create a new >>>>>>>> document from the parsed file, I can successfully update the data (Response >>>>>>>> Code: 200, Response Message: OK). >>>>>>>> >>>>>>>> Why can I not put data successfully on the server with >>>>>>>> xmlOutputter.output(docForPosting, http.getOutputStream())? >>>>>>>> >>>>>>>> Your help will be appreciated. My code is below: >>>>>>>> >>>>>>>> >>>>>>>> package myJDom; >>>>>>>>> >>>>>>>>> import org.jdom.*; >>>>>>>>> import org.jdom.input.DOMBuilder; >>>>>>>>> import org.jdom.input.SAXBuilder; >>>>>>>>> import org.jdom.output.XMLOutputter; >>>>>>>>> import org.xml.sax.SAXException; >>>>>>>>> >>>>>>>>> import java.io.File; >>>>>>>>> import java.io.FileWriter; >>>>>>>>> import java.io.IOException; >>>>>>>>> import java.net.Authenticator; >>>>>>>>> import java.net.HttpURLConnection; >>>>>>>>> import java.net.URISyntaxException; >>>>>>>>> import java.net.URL; >>>>>>>>> import java.net.URLConnection; >>>>>>>>> import java.util.ArrayList; >>>>>>>>> import java.util.List; >>>>>>>>> >>>>>>>>> import javax.xml.parsers.DocumentBuilder; >>>>>>>>> import javax.xml.parsers.DocumentBuilderFactory; >>>>>>>>> import javax.xml.parsers.ParserConfigurationException; >>>>>>>>> >>>>>>>>> public class MyJDomParser { >>>>>>>>> protected List rawElementList = new >>>>>>>>> ArrayList(); >>>>>>>>> protected List scrubbedElementList = new >>>>>>>>> ArrayList(); >>>>>>>>> protected List newElementList = new >>>>>>>>> ArrayList(); >>>>>>>>> protected SAXBuilder saxBuilder = new SAXBuilder(); >>>>>>>>> protected DOMBuilder domBuilder = new DOMBuilder(); >>>>>>>>> protected Document rawDoc = new Document(); >>>>>>>>> protected Element element; >>>>>>>>> >>>>>>>>> @SuppressWarnings("unchecked") >>>>>>>>> public void parseUrl() throws JDOMException, IOException { >>>>>>>>> System.out.println("preparing to parse the elements..."); >>>>>>>>> URL url = new URL( >>>>>>>>> " >>>>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>>>> "); >>>>>>>>> saxBuilder.setIgnoringElementContentWhitespace(true); >>>>>>>>> rawDoc = saxBuilder.build(url); >>>>>>>>> >>>>>>>>> element = rawDoc.getRootElement(); >>>>>>>>> rawElementList.addAll(element.getChildren()); >>>>>>>>> >>>>>>>>> for (int i = 0; i < 3; i++) {// remove 2 useless elements >>>>>>>>> rawElementList.remove(0); >>>>>>>>> } >>>>>>>>> >>>>>>>>> for (int i = 0; i < rawElementList.size(); i++) { >>>>>>>>> String s = rawElementList.get(i).getText(); >>>>>>>>> if (s != null && s != "") { >>>>>>>>> scrubbedElementList.add(rawElementList.get(i)); >>>>>>>>> } >>>>>>>>> } >>>>>>>>> >>>>>>>>> for (Element e : scrubbedElementList) { >>>>>>>>> System.out.println(e.getText()); >>>>>>>>> } >>>>>>>>> // for (Element e : rawElementList) { >>>>>>>>> // System.out.println(e.getText()); >>>>>>>>> // } >>>>>>>>> } >>>>>>>>> >>>>>>>>> public void getAllChangedElements() throws URISyntaxException { >>>>>>>>> System.out.println("preparing to change the data..."); >>>>>>>>> Element entry = new Element("entry"); >>>>>>>>> entry.addNamespaceDeclaration(Namespace.getNamespace("")); >>>>>>>>> newElementList.add(entry); >>>>>>>>> // rawElementList.add(entry); >>>>>>>>> >>>>>>>>> for (int i = 0; i < scrubbedElementList.size(); i++) { >>>>>>>>> String s = scrubbedElementList.get(i).getText(); >>>>>>>>> String name = scrubbedElementList.get(i).getName(); >>>>>>>>> if (s != null && s != "") { >>>>>>>>> if (name == "AccountName") { >>>>>>>>> s = "****55555******"; >>>>>>>>> } >>>>>>>>> Element e = new Element(name); >>>>>>>>> e.setText(s); >>>>>>>>> newElementList.add(e); >>>>>>>>> } >>>>>>>>> } >>>>>>>>> // return newData; >>>>>>>>> // for (Element e : newElementList) { >>>>>>>>> // System.out.println(e.getText()); >>>>>>>>> // } >>>>>>>>> } >>>>>>>>> >>>>>>>>> public void postData() throws IOException, JDOMException, >>>>>>>>> ParserConfigurationException, SAXException { >>>>>>>>> // building a document from DOM >>>>>>>>> DocumentBuilderFactory dbfac = >>>>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>>>> DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); >>>>>>>>> org.w3c.dom.Document docPrepareToPost = >>>>>>>>> docBuilder.newDocument(); >>>>>>>>> >>>>>>>>> // create my root element >>>>>>>>> org.w3c.dom.Element root = >>>>>>>>> docPrepareToPost.createElement("entry"); >>>>>>>>> docPrepareToPost.appendChild(root); >>>>>>>>> >>>>>>>>> // add elements to my dom doc >>>>>>>>> for (int i = 0; i < newElementList.size(); i++) { >>>>>>>>> org.w3c.dom.Element child = docPrepareToPost >>>>>>>>> >>>>>>>>> .createElement(newElementList.get(i).getName()); >>>>>>>>> child.setTextContent(newElementList.get(i).getText()); >>>>>>>>> root.appendChild(child); >>>>>>>>> } >>>>>>>>> >>>>>>>>> // parsing my doc from the file allows me a successful post >>>>>>>>> // FileWriter fs = new >>>>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>>>> // //posting is successful from this parsed file >>>>>>>>> // xmlOutputter.output(docForPosting, fs); >>>>>>>>> >>>>>>>>> DocumentBuilderFactory factory = >>>>>>>>> DocumentBuilderFactory.newInstance(); >>>>>>>>> docPrepareToPost = factory.newDocumentBuilder().parse( >>>>>>>>> new File("/home/rick/deleteme/crap2")); >>>>>>>>> >>>>>>>>> // setting up the stream >>>>>>>>> URL url = new URL( >>>>>>>>> " >>>>>>>>> http://192.168.1.199:3334/sdata/slx/dynamic/accounts(A6UJ9A000036) >>>>>>>>> "); >>>>>>>>> URLConnection connection = url.openConnection(); >>>>>>>>> connection.setDoOutput(true); >>>>>>>>> java.net.HttpURLConnection http = (HttpURLConnection) >>>>>>>>> connection; >>>>>>>>> http.setRequestMethod("PUT"); >>>>>>>>> HttpURLConnection.setFollowRedirects(true); >>>>>>>>> http.setRequestProperty("Content-type", >>>>>>>>> "application/atom+xml;type=entry"); >>>>>>>>> >>>>>>>>> // creating a JDom doc from the DOM doc to facilitate >>>>>>>>> streaming to the >>>>>>>>> // server >>>>>>>>> org.jdom.Document docForPosting = >>>>>>>>> domBuilder.build(docPrepareToPost); >>>>>>>>> >>>>>>>>> XMLOutputter xmlOutputter = new XMLOutputter(); >>>>>>>>> //this fails to update the data (Response Code: 200, >>>>>>>>> Response Message: OK) >>>>>>>>> xmlOutputter.output(docForPosting, http.getOutputStream()); >>>>>>>>> >>>>>>>>> //output seems ok >>>>>>>>> xmlOutputter.output(docForPosting, System.out); >>>>>>>>> //the printout seems ok >>>>>>>>> System.out.println("doctype = " + >>>>>>>>> docForPosting.getDocType()); //=null >>>>>>>>> FileWriter file = new >>>>>>>>> FileWriter("/home/rick/deleteme/crap2"); >>>>>>>>> //this successfully updates the data (Response Code: 200, >>>>>>>>> Response Message: OK) >>>>>>>>> xmlOutputter.output(docForPosting, file); >>>>>>>>> >>>>>>>>> System.out.println("Response Code: " + >>>>>>>>> http.getResponseCode()); >>>>>>>>> System.out.println("Response Message: " + >>>>>>>>> http.getResponseMessage()); >>>>>>>>> } >>>>>>>>> >>>>>>>>> public static void main(String[] args) { >>>>>>>>> MyJDomParser parser = new MyJDomParser(); >>>>>>>>> Authenticator.setDefault(new MyAuthenticator()); >>>>>>>>> try { >>>>>>>>> parser.parseUrl(); >>>>>>>>> parser.getAllChangedElements(); >>>>>>>>> parser.postData(); >>>>>>>>> } catch (JDOMException e) { >>>>>>>>> e.printStackTrace(); >>>>>>>>> } catch (IOException e) { >>>>>>>>> e.printStackTrace(); >>>>>>>>> } catch (URISyntaxException e) { >>>>>>>>> e.printStackTrace(); >>>>>>>>> } catch (ParserConfigurationException e) { >>>>>>>>> e.printStackTrace(); >>>>>>>>> } catch (SAXException e) { >>>>>>>>> e.printStackTrace(); >>>>>>>>> } >>>>>>>>> } >>>>>>>>> } >>>>>>>>> >>>>>>>> >>>>>>>> *Output (snipped):* >>>>>>>> >>>>>>>> preparing to change the data... >>>>>>>>> >>>>>>>>> >>>>>>>> />0001-01-01T00:00:00+00:00**------**2009-01-16T12:38:38+00:00****55555********SHORTENED**2008-10-21T09:01:41+00:00U6UJ9A000009ADMIN >>>>>>>>> 2008-10-31T13:25:58+00:002009-01-16T12:38:38+00:00ADMIN >>>>>>>>> ActiveCorporateMr.BobSmithMaleI.D.7904055766543RSA >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> To control your jdom-interest membership: >>>>>>> >>>>>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>>>>>> >>>>>> >>>>>> >>>>> >>>> >>>> _______________________________________________ >>>> To control your jdom-interest membership: >>>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >>>> >>> >>> >> >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090127/56de4bcf/attachment.htm