f



Retrieving XML path text values

Trying to write a function to get all values from a XML path without using a 
third party XPath libraries

Using jdk1.4 and wondering if it supports XPaths?
If so would prefer that as a solution instead of writing a recursive one myself

Thanks

An example of a start that I'am trying below


public static String[] getValue(Document doc, String path) throws Exception {
   String[] nodeNames = path.split("[\\/]");

   for (int i = 0 ; i < nodeNames.length ; i++) {
      String nodeName = nodeNames[i];
      NodeList elements = doc.getElementsByTagName(nodeName);
   }
}
0
akhalil1 (29)
1/27/2004 6:00:53 AM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

2 Replies
651 Views

Similar Articles

[PageSpeed] 32

Abraham Khalil wrote:
> Trying to write a function to get all values from a XML path without using a 
> third party XPath libraries
> 
> Using jdk1.4 and wondering if it supports XPaths?
> If so would prefer that as a solution instead of writing a recursive one myself

Unfortunately there is no standard way to apply an XPath expression to 
an org.w3c.dom.Node.  However, the implementation of javax.xml.* that 
ships with Sun's JDK is Xalan, which does include nice XPath support. 
So if you're using Sun's JDK, you can write code like

import org.apache.xpath.XPathAPI;
import org.w3c.dom.*;

// find the first node matching an XPath expression in
// the subtree starting at "node"
Node getNode(Node node, String xpathExpr) throws Exception {
   return XPathAPI.selectSingleNode(node, xpathExpr);
}

// get the string value of an XPath expression
String getNodeValue(Node node, String xpathExpr) throws Exception {
   return XPathAPI.eval(node, xpathExpr).str();
}

Even if you are using a JDK that doesn't come with Xalan, you can get it 
free from http://xml.apache.org.  The license allows it to be used in 
commercial products, so I see no reason to write your own XPath 
interpreter, except for fun.

> An example of a start that I'am trying below
> 
> 
> public static String[] getValue(Document doc, String path) throws Exception {
>    String[] nodeNames = path.split("[\\/]");
> 
>    for (int i = 0 ; i < nodeNames.length ; i++) {
>       String nodeName = nodeNames[i];
>       NodeList elements = doc.getElementsByTagName(nodeName);
>    }
> }

That's a start, but I bet pretty soon you'll want to evaluate more 
complex XPath expression, and next thing you know you'll be implementing 
your own XPath interpreter.  Unless you're doing it for fun, I don't see 
  the point since Xalan works well already.

Adam

0
adam25 (48)
1/27/2004 4:14:25 PM
Check out this old article.

http://www.fawcette.com/xmlmag/2001_12/magazine/columns/javabreak/

(watch the wrap)

"Abraham Khalil" <akhalil@pacific.net.au> wrote in message
news:b7f36ade.0401262200.450359d5@posting.google.com...
> Trying to write a function to get all values from a XML path without using
a
> third party XPath libraries
>
> Using jdk1.4 and wondering if it supports XPaths?
> If so would prefer that as a solution instead of writing a recursive one
myself
>
> Thanks
>
> An example of a start that I'am trying below
>
>
> public static String[] getValue(Document doc, String path) throws
Exception {
>    String[] nodeNames = path.split("[\\/]");
>
>    for (int i = 0 ; i < nodeNames.length ; i++) {
>       String nodeName = nodeNames[i];
>       NodeList elements = doc.getElementsByTagName(nodeName);
>    }
> }

0
news20041 (1)
1/27/2004 4:25:44 PM
Reply:

Similar Artilces:

Non-XML tagged value text to XML
I would like to use XSLT to translate some tagged value text to XML elements like this: Input Doc: <data>x=1.234 y=ABC z="Hello World"</data> Output Doc: <x>1.234</value> <y>ABC</y> <z>&quot;Hello World&quot;</z> Is XSLT up to the task? What would it look like? Most of the XSLT string processing code I've seen looks very verbose - can't be too efficient. mikea_59 wrote: > I would like to use XSLT to translate some tagged value text to XML > elements like this: > > Input Doc: > > <data>...

java.lang.UnsatisfiedLinkError: no lsxbe in java.library.path
Hello i got following exception: java.lang.UnsatisfiedLinkError: no lsxbe in java.library.path My source code looks like the examples of the Notes homepage. import lotus.domino.*; public class Main extends NotesThread{ public static void main(String argv[]){ System.err.println(System.getProperty("java.library.path")); // System.load("C:/Programme/lotus/notes/lsxbe.dll"); Main t = new Main(); t.start(); } public void runNotes(){ try{ Session s = NotesFactory.createSession("localhos...

java.lang.UnsatisfiedLinkError: no lsxbe in java.library.path
Hello i got following exception: java.lang.UnsatisfiedLinkError: no lsxbe in java.library.path My source code looks like the examples of the Notes homepage. import lotus.domino.*; public class Main extends NotesThread{ public static void main(String argv[]){ System.err.println(System.getProperty("java.library.path")); // System.load("C:/Programme/lotus/notes/lsxbe.dll"); Main t = new Main(); t.start(); } public void runNotes(){ try{ Session s = NotesFactory.createSession("localhost&qu...

java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
make sure you have the LD_LIBRARY_PATH set to include $ORACLE_HOME/lib... throw something like export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib in your .bashrc ...

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

java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace: java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method) at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:245) at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:130) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Cla...

Retrieve data from a text file, incrementing the last value and save new value below
Hi &nbsp; This was working initially. It is part of my LabView Project. I was trying to create a unique number that increments every time the adds the value to the list. It works on&nbsp;computer perfectly. But when I put this on a PDA, it seems to create a blank space when reading the contents of the text file after the last value, which means 0 + 1, which is not what I want. Please run the testUniqueNoOnPDA.vi first and change the path to C:\uniqueNumber.txt and save the uniqueNumber.txt file to your C drive and see What I am trying to do. Click the Enter button to increment. Why doe...

How to retrieve XML CDATA text contents by org.xml.sax.ext.DefaultHandler2?
For example I have a XML tag <script> <![CDATA[ My script is here ]]> </script> I am using org.xml.sax.ext.DefaultHandler2 to parse my XML file. How do I retrieve my script contents? What shall I do in these two methods? @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("script")) { // How to retrieve my script contents? } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equals("script")) { ...

java.lang.UnsatisfiedLinkError: no HwAPI_64 in java.library.path for jdk 1.6 on hpux
I had installed jdk 1.6 on hpux. I specified LD_LIBRARY_PATH and CLASSPATH on bash. I copied the libHwAPI.sl JNI shared library file to /opt/java6/jre/ lib/ext. Please help to fix "no HwAPI_64 in java.library.path" error. $ java -version java version "1.5.0.08" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0.08- _04_may_2007_06_31) Java HotSpot(TM) Server VM (build 1.5.0.08 jinteg:05.04.07-11:53 IA64, mixed mode) $ which java /usr/bin/java $ ls -ld /usr/bin/java lrwxr-xr-x 1 root sys 25 Mar 12 12:42 /usr/bin/ java -> /opt/java1.5/jre/b...

java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460)
Hi All I am having the torque3.1.jar and postgresql-7.4. I have compiled the new jdbc driver called as postgresql.jar and have placed it in the lib directory from where the ant scripts catch the jars. Whenever i try to access through torque gestList = BaseGestlistPeer.doSelect(new Criteria()); this error arises java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460) at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653) at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java...

java.lang.Set with elements of type java.lang.Set
Roughly I do something along the lines of: Set set = new HashSet(); Set elem = new HashSet(); set.add(elem); // now we change the elem and add it again to the set elem.add(some object here); set.add(elem); I found out the hard way that 'set' may now contain 'elem' either once or twice, the reason being that 'elem.add()' changes the hashCode of elem such that it is not noticed that it is in 'set' already on the 2nd 'set.add()'. Question: What I would actually want is an IdentityHashSet() set = new IdentityHashSet() but this does not...

How to modify a text value in a xml?
Hi, folks I met a problem with xml. I can't write to the file directly, here is my code: f = File.open(FILE_NAME) xml = REXML::Document.new(f) xml.root.each_element do |xml| xml.each_element do |node| #if the node name equal to Properties if node.name == "Properties" node.each_element do |child| #Get the child of Properties if child.name == "Name" #If the text equal to English, modified to the text to ABC if child.get_text == "English" #What should I put here? chil...

enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)
My question can be found here: http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python Here is an additional sample sample of the XML that I am working with: <Response ID="123546 - 7831" RequestType="Moverview"> <MonthDayCount> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32...

to use import java.lang.* or import java.lang.Math or none at all?
Hi guys, i knew that by default all java.lang classes will be imported by the compiler during compilation. but, to make it easier for the computer, should i specify which class i really will be using? does this action will boost the performance during compilation and runtime or not a matter at all? the answer to this post will definitely affect my programming style in the future when i'm considering "to import or not to import"... hmm,,, thanks in advance. JPractitioner wrote: > i knew that by default all java.lang classes will be imported by the > compiler during compilation. but, to make it easier for the computer, > should i specify which class i really will be using? does this action > will boost the performance during compilation and runtime or not a > matter at all? Whether and how you import classes has exactly zero effect at runtime. Imports (with or without wildcards) are only a kind of abbreviation provided by the compiler to save us the effort of typing in fully-qualified type names every time. In theory explicit importing should make compilation faster -- by a very tiny amount. I've never heard anyone claim that they've even managed to measure a difference let alone found a case where it made a practical difference. So the question comes down to how to write your code for maximum clarity. One school of thought asserts that you should always import each class explicitly (rather than by a wildcard). There's a fai...

Retrieving the value of a readonly text field
Hi all. I'm not sure why I'm having problems with this but if I try to retrieve the value of a readonly text form I get back that the object is undefined. The reason the text is readonly is because it's a date which I set via a calendar javascript program (associated with a button) only so the user can't put something silly in requiring validation. The form send the data correctly when submitted it just doesn't seem to be able to be read. I'm sure I'm missing something simple but I can't seem to find it. Thanks in advance for any help. All the best, Tony ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object
I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these commands: # zcat jdk-6u7-solaris-sparc.tar.Z | tar -xf - # pkgadd -d . SUNWj6rtx SUNWj6dvx SUNWj6dmx # /usr/jdk/instances/jdk1.6.0/bin/sparcv9/java -version Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object # ls /usr/jdk/instances/ jdk1.5.0 jdk1.6.0 # uname -a SunOS sun1 5.10 Generic sun4u sparc SUNW,Sun-Blade-2500 Please help to fix the error. Thanks. TsanChung wrote: > I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these > commands: > # zcat jdk-6u7-solaris-sparc.tar.Z | tar -xf - > # pkgadd -d . SUNWj6rtx SUNWj6dvx SUNWj6dmx > > # /usr/jdk/instances/jdk1.6.0/bin/sparcv9/java -version > Error occurred during initialization of VM > java/lang/NoClassDefFoundError: java/lang/Object It's missing or can't find rt.jar, right? How does the Solaris version find it's runtime files? Can you show us where rt.jar is? On Aug 20, 6:24=A0pm, Mark Space <marksp...@sbc.global.net> wrote: > TsanChung wrote: > > I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these > > commands: > > # zcat jdk-6u7-solaris-sparc.tar.Z | tar -xf - > > # pkgadd -d . SUNWj6rtx SUNWj6dvx SUNWj6dmx > > > # /usr/jdk/instances/jdk1.6.0/bin/sparcv9/java -version > > Error occurred during initialization of VM > > java/lang/NoClassDefFoundError: java/lang/Object > > It'...

[XML] filling empty attribute values with the default value specified in the XML schema.
Hello, I was wondering if there is an easy possiblity to configure a XML parser to automatically set empty attribute values to the default value specified in the xml schema file. I am currently using the dom4j framework with the validating Xerces2 SAX2 Parser. Thanks in advance, Stefan Siegl "Stefan Siegl" <Stefan.Siegl@gmx.de> wrote in message news:bg37d2$kd5qt$1@ID-151500.news.uni-berlin.de... > Hello, > > I was wondering if there is an easy possiblity to configure a XML parser > to automatically set empty attribute values to the default value > specif...

2008 computers.lang for java.programmer
jwehnf iuwhhttp://www.freewebs.com/thuiss/http://indianfriendfinder.com/go/g906725-pmem ashik wrote:Sub: 2008 computers.lang for java.programmerYou have nothing of value to anybody here. Pleasestop wasting our bandwidth.Further, please don't become the latest in a long line of perennial spamming f*ckw*t morons who infestthis usenet newsgroup.-- Andrew Thompsonhttp://www.physci.org/Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200711/1 Andrew Thompson wrote:> ashik wrote:> > Sub: 2008 computers.lang for java.programmer> > You have nothing of...

Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object
Good day to all, I have installed the j2se/netbeans binary bundle on red hat 9. I can run everything perfectly as root but when I try to compile with any other user I get: Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object When I saw this it seemed like a permissions problem but I checked the permissions and everything seemed fine. All users have execute permissions of javac and java. I have read other threads dealing with the same or similar problem but have not reached any solution yet. I would appreciate if anyone that has run into this type o...

Retrieve and calculate values from XML file
I have an XML files that contains grades in different subjects from year 2005 =13 2007 . In the HTML file I have several drop down list that contain all the names of the subjects. If I select for example history from the first one , I get the grade for 2005 in the first field, then the grade for 2006 in the field next to it and the grade for 2007 in the third field. Then I go to the second drop down list , select another subject name and get all related grades in the proper fields. So I have a page with approximately ten drop down list. Now I have some fields in addition that presents calcul...

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Hi, I'm trying to use the httpclient within Jython (see http://jakarta.apache.org/commons/httpclient/ for more information on the httpclient). My Jython version is: Jython 2.1 on java1.4.2_04 (JIT: null) My Java version is: java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode) My CLASSPATH includes: jdom.jar xerces.jar jython.jar jt400.jar log4j-1.2.8.jar commons-httpclient-2.0.jar When I just try to perform the import statements from example code I get the error pasted below....

CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error. My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass". Thank you, compile: run: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412) at javax.swing.JTable.prepareRenderer(JTable.java:5735) at javax.swing.plaf.basic.BasicTableU...

Retrieving values of text boxes within a GUI
Hi there. I'm trying to create a GUI which captures input from a user and then uses this data to call another function which does some data preprocessing. I capture the input from the text box using the callback function and save it using the code below: function window_size_Callback(hObject, eventdata, handles) % hObject handle to window_size (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of window_size as text % str2double(g...

Web resources about - Retrieving XML path text values - comp.lang.java.programmer

Mother of three killed landlord after he tried to stop her retrieving her son's shirt
A mother of three has been found guilty of killing her landlord after he tried to stop her retrieving a red polo shirt her son needed for school ...

Retrieving bodies a 'horrifying' experience (01:43)
Anti-jump measures on the Story Bridge should be "fast tracked" and water police funding increased so CityCats don't have to pick up bodies. ...

Man drowns retrieving toy boat
A man has drowned after entering the Wimmera River at Horsham to retrieve a remote-controlled boat.

Bishop says there is no time limit on retrieving MH17 remains
THE Australian Federal Police have warned that it is too dangerous to approach the MH17 crash site in war-torn eastern Ukraine until security ...

Search underway for man swept away in Brisbane River while retrieving toy boat
A search is underway for a man swept away in the Brisbane River while retrieving a toy boat.

DPRK blames US for suspension of retrieving American soldiers' remains
DPRK blames US for suspension of retrieving American soldiers' remains People's Daily Online PYONGYANG, Oct. 13 The Democratic People's Republic ...

Father killed retrieving Christmas gifts from broken-down car
Richard Perrin, 57, was struck and killed by another driver early Saturday along Hwy 170 in Roanoke.

Yankee retrieving a big Canada
Yankee retrieving a big Canada

iPhone dev: Retrieving user phone numbers
... a secret to recovering user phone numbers that does not involve the … One of the most common questions I get these days has to do with retrieving ...

Girl stuck in Dover storm drain retrieving phone
A teenage girl gets stuck in a storm drain in Dover while trying to retrieve her mobile phone which had fallen into it.

Resources last updated: 2/25/2016 10:42:41 AM