• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Parsing Issue

 
Jeremy Quartey
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone offer any advice on the following:
I get the error below on running a java project in JBuilder:
Error: problem with parsingElement "<DRAWCOMMANDS>" is not valid because it does not follow the rule, "(START|DRAWSQUARE|DRAWCIRCLE)*".
Document finished

The combined DTD and XML file is
<?xml version = "1.0" standalone = "yes" ?>
<!DOCTYPE DRAWCOMMANDS [
<!ELEMENT DRAWCOMMANDS (START|DRAWSQUARE|DRAWCIRCLE)*>
<!ELEMENT START EMPTY>
<!ELEMENT DRAWSQUARE EMPTY >
<!ELEMENT DRAWCIRCLE EMPTY>
<!ELEMENT DELETEALL EMPTY>
<!ATTLIST DRAWSQUARE
XPOS CDATA #REQUIRED
YPOS CDATA #REQUIRED
>
<!ATTLIST DRAWCIRCLE
XPOS CDATA #REQUIRED
YPOS CDATA #REQUIRED
>
]>
<DRAWCOMMANDS>
<START/>
<DRAWSQUARE XPOS = "14" YPOS = "120"/>
<DRAWCIRCLE XPOS = "20" YPOS = "30"/>
<DRAWCIRCLE XPOS = "120" YPOS = "50"/>
<DRAWSQUARE XPOS = "9" YPOS = "44"/>
<DRAWSQUARE XPOS = "66" YPOS = "130"/>
<DRAWSQUARE XPOS = "80" YPOS = "150"/>
<DELETEALL/>
</DRAWCOMMANDS>
The source code is designed to draw shapes:
if(elementName.equals("DRAWCIRCLE"))
{
//Get attributes
for(int j = 0;j<al.getLength();j++)
{
attributeName = al.getName(j);
attributeValue = al.getValue(j);
if(attributeName.equals("XPOS"))
xPos = Integer.parseInt(attributeValue);
if(attributeName.equals("YPOS"))
yPos = Integer.parseInt(attributeValue);
}
//Draw a circle
df.addCircle(new DrawnCircle(xPos, yPos));
//df is a frame object
}
//Circle encountered
if(elementName.equals("DRAWSQUARE"))
{
//Get attributes
for(int j = 0;j<al.getLength();j++)
{
attributeName = al.getName(j);
attributeValue = al.getValue(j);
if(attributeName.equals("XPOS"))
x = Integer.parseInt(attributeValue);
if(attributeName.equals("YPOS"))
y = Integer.parseInt(attributeValue);
}
//Draw square
df.addSquare(new DrawnSquare(x, y));
df.displaySquaresAndCircles();
}
I am not sure whether the format for START is correct and I still need to make sure DELETALL is correct
Any help will be gratefully accepted
Regards
Jeremy
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The document is not valid.
You can make it valid by changing the DRAWCOMMANDS element definition to be -

Cheers,
Dan
 
Jeremy Quartey
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan - I will try that !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic