java + XML + dom4j

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi,I have an XML file like this:articleSet article   title    /title   author   /author /article article    title    /title   author   /author /article/articleSetusing dom4j I put this XML into a org.dom4j.Document (named xmlDoc) andfor each "article" Node I wuold like to do some stuff so I wrote this codeIterator iter = xmlDoc.selectNodes("//article").iterator();	while(iter.hasNext()){		Node n = (Node)iter.next();		System.out.println(n.asXML());                System.out.println(n.selectSingleNode("//title").getText());	}the problem is that the first "println" prints correctly the content ofeach "article" Node but the second prints always the FIRST article titlebecause the XPath search is done on entire document and not only insidethe current node.Why this behaviour? I made some mistakes?dat
0
Reply dat 10/16/2007 3:19:31 PM

See related articles to this posting

comp.lang.java.programmer 52097 articles. 40 followers. Post

0 Replies
174 Views

Similar Articles

[PageSpeed] 10


Reply:

Similar Artilces:

Xml parsing with dom4j in java
Hi everyone, i have to debug this part of a program that doesn't wanna work fo is a variable Concept that has inherited the metods elements() element() from AbstractElement of dom4j fo has this structure fo is written in owl that is very similar to xml <and xmlns=" http://dl.kr.org/dig/2003/02/lang"> <catom name="Nautical_equipments"/> <all> <ratom name="has_anchor_windlass"/> <and> < catom name="Anchor_windlass"/> <catom name="Electric_Anchor_windlass"/> </and> ...

How to generate xml using a xml schema in java?
Hi I need some help in generating xml using a valid xml schema in java. I am already doing parsing of an xml request using xerces parser's. Now I need to send xml response back , i have all the fields and values(attribute's) in a HashTable. Thanks Raj ...

Generate an XML in Java using an XML Schema
Hi, Is it possible to create an XML in Java using an XML Schema? Is the XML Schema just for validation? Thanks! V <vmtigno@yahoo.com> wrote in message news:1145378572.065788.33540@u72g2000cwu.googlegroups.com... > Hi, > Is it possible to create an XML in Java using an XML Schema? Is the XML > Schema just for validation? The question isn't entirely clear to me. What you can do is assist the user in creating an XML file, essentially by continuously validating whatever they type against the schema. Another possibility is to analyze the schema, and then generate a mi...

mapping java type java.util.Map to XML
I am devoloping a webservice application using jax-ws2.1I want write a wsdl and xsd file which applyed the follow functionpublic void addElement(String id,Map<String,String> repos){...................}relevant chip of wsdl<message name="addElement"> <part name="parameters" element="tns:addElement"></part></message><portType name="..."> ........ <operation name="addElement"> <input message="tns:addElement"></input> <output message="tns:addElementResponse"><...

Convert Java Model to Java Model without XML
Is there a way to convert a Java model to anyother java model without XML? I am planning on converting Java data model-> xml->xslt->xml->java data model I'd like to cut out the xml part and replace the xslt with something that can do a straight data model to data model conversion. Is there some mechanism that does this? If there isn't, why doesn't one exits? erinbot@gmail.com wrote: > Is there a way to convert a Java model to anyother java model without > XML? > > I am planning on converting Java data model-> xml->xslt->xml->java data > ...

Generate an XML in Java using an XML Schema #2
Hi, Is it possible to create an XML in Java using an XML Schema? Is the XML Schema just for validation? Thanks! V On Tue, 2006-04-18 at 09:43 -0700, vmtigno@yahoo.com wrote: > > Is it possible to create an XML in Java using an XML Schema? Is the > XML > Schema just for validation? Well, XML Schema isn't "just" for validation. It defines the structure that a given document may have, which happens to be useful for validation. I use Castor to generate java objects from XSD. Those objects are essentially beans, which can be marshalled or unmarshalled to or from X...

XML to XML
I have a gnucash file that I'm trying to transform into an identical XML file without the invoices. I've been at this for a while now. The gnucash file is in XML and the element I'm looking into is: <gnc:transaction> I want to ignore those that contain <slot:key>gncInvoice</slot:key> which is a child of slot which is a child of slots which is a child of transactions. Any help you're willing to provide would be greatly appreciated. Thanks. Classic application for XSLT. Start with the identity transformation, then add a template which matches the ones yo...

Xml and java
Hi there, i need for some snippet of java codes, that from a xml file like this: <People> <Employ> John Denver </Employ> ...A subtree.... <Employ> Mike Harris> </Employ> ....Another subtree.... <Employ> Mark White </Employ> .....More subtree.... </People> Extract an employ of given key (i.e. John Denver) with its subtree in a string. Is this a simple thing? Thanks for the attention, Awy ...

Java with xml
Hi guys, I am wondering which library to use to manipulate xml files in Java. Cheers. <glin@tollnz.co.nz> wrote in message news:1110155566.158569.77480@o13g2000cwo.googlegroups.com... > Hi guys, I am wondering which library to use to manipulate xml files in > Java. GNU JAXP - The GNU Project Lark - Tim Bray Piccolo - Yuval Oren Xerces Java - The Apache XML Project XP - James Clark (Java 1.1) XML Pull Parser - Aleksander SlominskiJava and C++ JDOM Crimson ´┐Żlfred .... take your pick... (At least I've given you some food for Google....

XML/Java
Hello, I have this XML file below and I want to read the data from the XML file in my java code when I connect to my database in my java code. How do i do that ? ---XML File <db> <databaseName>opsa</databaseName> <username>User</username> <password>Pass</password> </db> ------database.java public void ConnectToDatabase() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn= DriverManager.getConnection ("jdbc:odbc:opsa", "", ""); stmt = conn.createStatement();...

xml to java object to xml - is xmlbeans ok?
hello there can any one tell regarding the performance issues in using xmlbeans in converting xml to java to xml for a project to be done in websphere environment. is there any other best api for the process of conversion of xml to java to xml more efficient than xmlbeans. thanks Ananth On Tue, 17 Oct 2006 05:26:53 +0100, ananth <anboss@gmail.com> wrote: > hello there can any one tell regarding the performance issues in using > xmlbeans in converting xml to java to xml for a project to be done in > websphere environment. is there any other best api for the process of > con...

Java in Java
Is it possible to download a Java app (applet etc?) and run it inside a desktop Java app? -- Dirk http://www.transcendence.me.uk/ - Transcendence UK http://www.theconsensus.org/ - A UK political party http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff Dirk Bruere at NeoPax wrote: > Is it possible to download a Java app (applet etc?) and run it inside a > desktop Java app? > Quite likely, but you won't necessarily get the same security model, unless you were careful about it. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/&g...

framework for marsheling java beans to xml accroding to xml Schema?
hi.. is there a framework, that given a java bean and an xml schema from a wsdl, would be able to marhsall it correctly according to that schema? ( i need to convert it later to an OMElement of axis) On Jan 6, 8:37=A0am, elh.maa...@gmail.com wrote: > hi.. > > is there a framework, that given a java bean and an xml schema from a > wsdl, would be able to marhsall it correctly according to that schema? > ( i need to convert it later to an OMElement of axis) An XML schema imposes constraints on the contents of an XML document but does not define a mapping of arbitrary data to th...

Java to XML
Is there a parser which converts Java Source Code to XML? -- Sebastian Danicic web: http://www.doc.gold.ac.uk/~mas01sd Department of Computing, e-mail: s.danicic@gold.ac.uk Goldsmiths College, Dept web: http://www.doc.gold.ac.uk University of London, tel +44(0)207 9197868 London SE14 6NW. fax +44(0)870 0514569 Sebastian Danicic wrote: > Is there a parser which converts Java Source Code to XML? This might be of some use: http://www.www9.org/w9cdrom/342/342.html Richard ...

XML or not XML?
I am developing a simple MySQL database editor, and am looking into creating an PHP/AJAX app as the GUI. A lot of this in new ground, and much more is dusting off things I haven't used in a while. My question though involves whether or nor to employ XML. I did some XML a few years back, but don't typically bother anymore. As I see it XML is great when I need to have an app with a standard data presentation that other developers can easily interface. I.E. like a bank statement that may feed a variety of applications developed by a variety of clients. However, if I am develo...

XML and Java
I'm getting very interested in XML, especially in using Java to create and update XML files. However, the documents I'm reading about XML at IBM Developer Works are, for the most part, quite dated with dates in 2002 and earlier being typical. How do I find out what the current practices are on XML and how to work with it in Java? I don't want to waste a lot of time trying to figure out how to use tools and techniques that have long since been replaced by far better techniques. For example, having to use DOM to read an entire XML document in order to insert a single element ...

xml in java
Hi all, i want to know, whether Microsoft SQL Server 2000 support "for xml" and "openxml" in java or not. If yes, how can i use it? Please help! thank you very much and greeting from germany! rabbit ...

Java Java
Have my first Open Source Linux Java Project. Working on a second right now. Coming out with a distro called OPEN*WINDOWS. It will be at www.black-and-company.com tab wrote: > Have my first Open Source Linux Java Project. > Working on a second right now. > > Coming out with a distro called OPEN*WINDOWS. > > It will be at www.black-and-company.com > Wasn't that the whole point of Lindows? Oh, right, we didn't care for that either. tab wrote: > Have my first Open Source Linux Java Project. > Working on a second right now. > > Coming out with a ...

java and XML
Hi I have the following bit of Java code: //Use JTidy implementation to create an empty Document object Document doc = tidy.createEmptyDocument(); //bodyElement is the body element in an HTML Document Node first = bodyElement.getFirstChild(); Node top = doc.getDocumentElement(); top.appendChild(first); which produces unexpected results. Basically, all I am trying to do is retrieve the first child node contained in the body element and copy it to the new document element. But what I get is the required element AND every element after it - every one of the first elements siblings! I have trie...

xml to java
i have an xml file like <node type="Service" key="1"> <value>Title</value> </node> <node type="Service" key="2"> <value>CA</value> </node> Can java parse through the xml file to create an object like VO.getNodeType VO.getKey VO.getValue timothy ma and constance lee (timcons1@shaw.ca) wrote: : i have an xml file like : <node type="Service" key="1"> : <value>Title</value> : </node> : <node type="Service" ...

To XML or not to XML?
Ok, it has been a while since I've needed to make an involved web page. Coming back on the scene now is a bit confusing, what with all the cool stuff to use like XML, PHP, MySQL, etc... So here is my question. I'm in search of a good dynamic way to generate web pages which separates content from presentation. I am seeking to create a web site that, to put it succinctly, has a list of users and sets of information corresponding to each user. I am familiar with how to do this using PHP, MySQL, and regular old HTML. I maintain the user database in MySQL and dynamically present it and th...

Java XML
I'm trying to import javax.xml into my program but ProjectBuilder gives my an error saying that the package does not exist. All of my other javax imports work except for this one. I'm using 10.2.8 with project builder 2.1. Anyone know why project builder cannot find this package? ...

java to XML
Has anyone written a parser from Java to XML? -- Sebastian Danicic web: http://www.doc.gold.ac.uk/~mas01sd Department of Computing, e-mail: s.danicic@gold.ac.uk Goldsmiths College, Dept web: http://www.doc.gold.ac.uk University of London, tel +44(0)207 9197868 London SE14 6NW. fax +44(0)870 0514569 Sebastian Danicic wrote: > Has anyone written a parser from Java to XML? > Yes, I have, It is documented here: http://www.euclideanspace.com/software/language/xes/ and can be loaded from: http://sourceforge.net/projects/xes/ I would welcome amy help...

java and XML
Hi I have the following bit of Java code: Document doc = tidy.createEmptyDocument(); //bodyElement is the body element in an HTML Document Node first = bodyElement.getFirstChild(); Node top = doc.getDocumentElement(); top.appendChild(first); which produces unexpected results. Basically, all I am after is getting the first child node of the body element and copy it to the new document. But what I get is the required element AND every element after it - every one of the first elements siblings! I have tried so many variations of the above, using DocumentFragments etc, but with no joy. In orde...