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 51876 articles. 38 followers. Post

0 Replies
152 Views

Similar Articles

[PageSpeed] 51


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 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...

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 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 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" ...

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...

ULC XML
Canoo released ULC XML, a tool that allows developers to create UltraLightClient user interfaces from XML files. ULC XML is a free and open-source tool for Canoo's Java RIA library. It is available for download at the ULC XML project site at Java.net. ULC XML is an UI generator for UltraLightClient applications. The XML file is parsed at runtime and rendered into Java objects. ULC XML is similar to the solution offered by the open source project SwiXml: Java classes are mapped to element names; property names translate into attribute names. Developers familiar with SwiXml have little effo...

ULC XML
Canoo released ULC XML, a tool that allows developers to create UltraLightClient user interfaces from XML files. ULC XML is a free and open-source tool for Canoo's Java RIA library. It is available for download at the ULC XML project site at Java.net. ULC XML is an UI generator for UltraLightClient applications. The XML file is parsed at runtime and rendered into Java objects. ULC XML is similar to the solution offered by the open source project SwiXml: Java classes are mapped to element names; property names translate into attribute names. Developers familiar with SwiXml have little effo...

ULC XML
Canoo released ULC XML, a tool that allows developers to create UltraLightClient user interfaces from XML files. ULC XML is a free and open-source tool for Canoo's Java RIA library. It is available for download at the ULC XML project site at Java.net. ULC XML is an UI generator for UltraLightClient applications. The XML file is parsed at runtime and rendered into Java objects. ULC XML is similar to the solution offered by the open source project SwiXml: Java classes are mapped to element names; property names translate into attribute names. Developers familiar with SwiXml have little effo...

Java, validate XML with XSD, XML not containing "xmlns:xsi=..."
I am using java to validate an XML file with a DTD, without having the DVD declaration inside the original file, by setting the doctype dynamically to a transformer like this : transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtd); transformer.transform(source, new StreamResult(new StringWriter())); I would like to know if there is a way to validate an XML file with an XSD, again, without having the declaration of the xsd file inside the original XML file, but by declaring it dynamically. Thank you ! killy971 schrieb: > I am using java to validate an XML file wit...

XML-RPC
Hello, I am getting an error "XML-RPC - java.lang.ClassCastException: java.util.Date" when I call the "XmlRpcClient" execute method. I believe the underlying classes are having trouble parsing the result from the time.xmlrpc.com/RPC2:80 XML-RPC service. I apologize that I could not navigate the Apache bug reporting and search system. I hope someone can recognize what is up with this. Thank you in advance for any help, Michael import java.util.Vector; import java.util.Hashtable; import org.apache.xmlrpc.*; public class GetTime { private final static String serv...