Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

re: XML query

 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted and answered here
 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic