wood burning stoves*
The moose likes XML and Related Technologies and the fly likes re: XML query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "re: XML query" Watch "re: XML query" New topic
Author

re: XML query

joe weakers
Ranch Hand

Joined: May 31, 2004
Posts: 38
Hi there. I do realize this is a java forum and not an XML forum but I thought I might just see if anybody can help me nonetheless. I am trying to parse thru XML files to extract certain detail from said files. The following is a snippet of the file type that I am parsing:

<useractions>
<mapaction>
<action_id>z03</action_id>
<feature_id>D21</feature_id>
<action_time>1088421430234</action_time>
</mapaction>
<layer>
<frame_number>1</frame_number>
<feature_id>D21</feature_id>
</layer>
<mapaction>
<action_id>z02</action_id>
<feature_id>D21</feature_id>
......
</useractions>.
and so on. I have the header and dtd set up as the file seems to be parsed correctly up till a certain point at least. It parses the first <mapaction></mapaction> and <layer></layer> perfectly. However I get the following error as soon as my code encounters the second <mapaction> tag. The error is as follows:

org.xml.sax.SAXParseException: Element "useractions" does not allow "mapaction" here. I realize that it is most likely the way I have defined my dtd. The dtd I am using is set up as follows:

<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for a simple "XML recording". -->

<!ELEMENT useractions (mapaction+, layer+)>
<!ELEMENT mapaction (action_id, feature_id*, action_time)>
<!ELEMENT action_id (#PCDATA)>
<!ELEMENT feature_id (#PCDATA | feature_id)*>
<!ELEMENT action_time (#PCDATA)>
<!ELEMENT layer (frame_number, feature_id*)>
<!ELEMENT frame_number (#PCDATA)>

I cannot see anything wrong here as useractions is defined to contain a series of mapaction elements and layer elements. However the program returns
an error as soon as the second mapaction is reached. Can anyone offer any suggestions please. Thanks Joe
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8710
    
    6

Crossposted and answered here


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
joe weakers
Ranch Hand

Joined: May 31, 2004
Posts: 38
Sorry about posting this message in the wrong spot. Just another brief query. When parsing thru my XML files which appear something like this:

<useractions>
<useraction>
<mapaction>
<action_id>z02</action_id>
<feature_id>D21</feature_id>
<feature_id>A51</feature_id>
<action_time>1088432695890</action_time>
</mapaction>
<layer>
<frame_number>1</frame_number>
<feature_id>D21</feature_id>
<feature_id>A51</feature_id>
</layer>
</useraction>
....
</useractions>

I appear to require 4 or 5 embedded for loops and if statements. I cannot see any alternative to extracting the innermost detail. I presume this is ok as the files become no more complicated then the snippet above and the progrma executes quickly enough.Thanks Joe
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by joe weakers:
I appear to require 4 or 5 embedded for loops and if statements. I cannot see any alternative to extracting the innermost detail.

You could also use an XPath library (Apache Xalan has one, for example) to pull out the information you need.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: re: XML query
 
Similar Threads
Editing dtd file to allow certain elements but not use them in a tree display.
Quick question
parsing GML using SAXParser
question on mock exam
DTD and XML