Jeff Grant

Ranch Hand
+ Follow
since Dec 19, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jeff Grant

Thank you for your comments Paul.

I will look into using XSLT instead of XPath. I'm hoping there is not too much code variance between the two.

Originally posted by Paul Clapham:
Well, yes, the XPath expression you have in that element does return a string, whereas "/a/c" returns a node list. So you can't pass its result to something that's expecting a node. You'll need to fix your design.


Hmm. Do you think it is best that I create my own string parsers then?.. such as I accept the object "substring("/a/b",1,3) and deal with that myself in the code rather than relying on the classes doing it for me?

I'm very new to XML but understand how it works with open and close tags, attributes, values, etc. I just have run into trouble seeing as the system I am implementing this on cannot be upgraded to Java 1.5 and that's what a lot of the information on the web speaks about now since it has javax.xml.xpath built in.

Originally posted by Paul Clapham:
You started out with a lot of description, but it just seems to be background and you don't have any description of your actual problem that I can see. However my diagnosis is, instead of trying to write a generic XPath evaluator where you're going to keep hitting problems every time you try to add a new feature, why not just put those things into an XSL transformation and just run that?


I'm sorry that I got a little lax on the description. I'm simply looking to have my XPath expression perform a test on one XPath expression. Pending the result of that test, I would then want the result of one XPath or another to be the one which is actually being the returned value. Perhaps this is a better example in layman's terms.

So this code block would have to perform the /a/b query, then compare it to 7. If /a/b is in fact 7, it would get the value of /c/d and return it to the XPath query, otherwise it would get the value of /e/f and return that.
I've been working on an XML parser application for a while now. However, now I have run into a couple of things which I cannot seem to get to work.

Here is a snippet of my XML read code.


Here is a snippet of my XML expression file which I am attempting to add a condition to in order to later parse my XML data file. This does currently work (it's within other beans and such of course).


Okay, so the expressions currently work as expected recalling the element requested. The setExpressions method being called stores an array of type Object.

The first thing I was looking to do was parse the returned element. Such as getting just the first three characters. To do this I attempted the following XML code change: <value>substring(/a/c,1,3)</value>. However, this throws an exception saying it is getting a #STRING instead of NODE object. I cannot seem to figure out how to pass this parsed result if it is possible.

The second thing I was looking to do was have a conditional statement based on other XML values in the document being parsed. For example, if element "/a/b" is equal to the string "AB" then we are actually looking to do "/a/d". Now for this I see things using XSL in the XML tags but it never successfully compiles let alone allow me to execute it. Any help on this would also be greatly appreciated.
That looks like a possibility as well Stan. Thanks for the suggestion.
18 years ago
Thanks for looking into this question for me since you had never heard of the class.

You mean you want to leave parts of the document unparsed? Doubt it. Parsers don't work that way. They convert XML to internal formats. You would have to serialize those bits back to XML if you wanted them that way.


Yes, that's what I'm looking for. The purpose is to parse out all data elements and local names from within a "transaction" set for another function to deal with the transaction itself to avoid cluttering a single "transaction getter" function.

I understand what you're saying though how that'd defeat the purpose of a parser.

"Storing in an array" versus "Reading from a file"? I don't see any contradiction or overlap between those two concepts. You can parse from pretty much anywhere, and you can store the data wherever you like. Maybe you mistyped something there?


Yeah, I definitely worded that poorly.

I have continued working on this issue this morning and found exactly what you said. I stored some XML in a string and read that into XMLStreamReader instead of reading from the file and it worked as was stored. So rather than a temporary file, I will likely store the XML into a string to save time.

So now here is where I am at since XML strings themselves seemingly cannot be pulled from the XMLStreamReader class. XML is plain text and the format of my XML file format is consistent, I am now thinking I will read it via FileInputStream and just look for the beginning and ending tags saving every line in between storing it into a single string as described above. Then I will be able to parse it with the XMLStreamReader in the next function to process the set.
18 years ago
I am attempting to use the javax.xml.stream.XMLStreamReader class to read an XML data file. I have it working correctly and giving all requested results. However, I would like to parse out certain subsections as XML without having to reconstruct it manually to then parse it elsewhere.

Here is an example.



From this example, I might want to retrieve all of "section2" to another class I've built to hold the nodes to then later reparse. I need it to retain it's XML format so I can continue using XMLStreamReader to parse it later on.

First question is if it's possible to get sub-elements actual XML rather than parsing based on local name and element text?

Section question is if this is possible to parse by storing in an array rather than reading from a file?.. if not, I will probably generate a temporary file to hold this retrieved information and then reparse it.

Thanks in advance for any suggestions. I am open to using another class if it is freeware and can do this requested task.

-Jeff

P.S. I am surprised at the lack of XMLStreamReader posts on JavaRanch! I only found one when searching all of JavaRanch via the google search feature.
18 years ago
I would place the contents of the combo box and list box in a multi-dimensional array. Lets say that column 0 would be the contents of the combo box and columns 1+ would be the list box. Then place an action listener on the combo box and populate the list box according to the selection.
19 years ago
Originally I was still doing my Buffered Read into a string to get the length of a single line and create a byte array of the appropriate length of that line.

But I expect there must be an easier/more efficient way.. suggestions?
19 years ago
Thank you very much Ernest. Changing my input from BufferedReader to FileInputStream has given me the proper results! Now I'm trying to move my application to use the FIS instead of the BR which is proving to be a little more quirky than just changing class names, but it's coming along nicely.

Thank you for your help!
19 years ago
I'm reading in data from a file which is "packed" (each two values packed into one bit). I can view this data with an unpack utility to verify that it is correct. However, when I bring it in to my Java app, it reads two characters in wrong.. ie: reads both 24 and 85 in as 45.

My method of reading in from the file is using BufferedReader.readLine() into a String variable and then using String.getBytes() to then begin parsing the string to "unpack" it.

As stated, it works in all cases except two values.

In an attempt to get a unique value for each so I can individually parse them, I have tried to out to the command line things like the ASCII value, Integer.decode, and String.hashCode... but they all seem to be read in as identicle values even though I have proven they are not identicle in my other viewer.

Any suggestions as to tests to try against the two in order to prove them not equal are appreciated and will be attempted.

If using BufferedReader into a string then getBytes is my problem, I will attempt to change it to your suggestion.

Thanks in advance.
19 years ago
int temp = Integer.valueOf(startDate.substring(8,9));
19 years ago
In the future, would have helped to print your stack trace so we could see exactly where the error was coming from.
19 years ago
I had the same problem with JOptionPane a while ago. Turned out that frame I was passing was in fact null during my default frame constructor.

I would make sure the "frame" you pass is not null.
19 years ago
Coincidentally, I just asked something related to this and posted code..

See this thread
[ May 24, 2005: Message edited by: Jeff Grant ]
19 years ago
GraphCanvas extends JPanel

I've been looking up Double Buffering on Google and it seems as though it is already being used with Swing.
19 years ago