• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

re: XML query

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposted and answered here
 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic