Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parse with commons digester

 
Carlos E Z Batistao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm think this is right forum to post this doubt
if i'm wrong, i'm sorry

i try to parse a xml file with validation using schema, like this:
<dictionary xmlns="http://www.atlantico.com.br/projeto-xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlantico.com.br/projeto-xml layouts.xsd" version="1.0">
<entry>
<from>1010</from>
<to>11</to>
<comment />
</entry>
</dictionary>

but when i run the program, his throw a exception
org.xml.sax.SAXParseException: Document root element is missing.


if i remove the attribuits on tag directory, it's work!!

who can i make the parse with validation schema on xml file!?
in attach the code of my class to make a parse(or try ) heheehhe

public DictionaryParser(String filePathName) throws IOException, SAXException {

// instantiate Digester and disable XML validation
Digester digester = new Digester();
digester.setValidating(false);

// instantiate AddressBookParser class
digester.addObjectCreate("dictionary", DictionaryParser.class );
// instantiate Contact class
digester.addObjectCreate("dictionary/entry", EntryXML.class );

// set different properties of Contact instance using specified methods
digester.addCallMethod("dictionary/entry/from", "setFrom", 0);
digester.addCallMethod("dictionary/entry/to", "setTo", 0);
digester.addCallMethod("dictionary/entry/comment", "setComment", 0);

// call 'addContact' method when the next 'address-book/contact' pattern is seen
digester.addSetNext("dictionary/entry", "addEntryInColleciton" );

// now that rules and actions are configured, start the parsing process
DictionaryParser abp = (DictionaryParser) digester.parse(new File(filePathName));
}


tks for help!!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i'm think this is right forum to post this doubt

We have an XML forum where this would be better placed. I'll move it there.


if i'm wrong, i'm sorry

Don't worry about it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic