DaveG
DaveG

Reputation: 484

Problems using commons digester to parse subversion XML output

The Subversion XML formatted output is a combination of attribute and elements - particularly within the <path> element - see the sample below:

<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry
   revision="29">
<author>bob</author>
<date>2013-02-14T17:21:42.848605Z</date>
<paths>
<path
   action="A"
   kind="dir"
   copyfrom-path="/trunk"
   copyfrom-rev="28">/tags/TAG-0.1</path>
</paths>
<msg>Creating tag TAG-0.1</msg>
</logentry>
</log>

I'm trying to use commons digester to parse this the log content into two different POJO's (LogEntry and Path) using the following:

ArrayList<LogEntry> logEntries = new ArrayList<LogEntry>();
    digester.push(logEntries);

    digester.addObjectCreate("*/logentry", LogEntry.class);
    digester.addSetProperties("*/logentry");
    digester.addBeanPropertySetter("*/logentry/author");
    digester.addBeanPropertySetter("*/logentry/date");
    digester.addBeanPropertySetter("*/logentry/msg");
    digester.addSetNext("*/logentry", "add");

    digester.addObjectCreate("*/logentry/paths/path", Path.class);    
    digester.addSetProperties("*/logentry/paths/path");
    digester.addBeanPropertySetter("*/logentry/paths/path", "value");
    digester.addSetNext("*/logentry/paths/path", "addPath");

(note addPath adds the path object being created onto an ArrayList<Path> within the created LogEntry object)

I can't figure out why the Path class is not being fully populated. Based upon the XML I can understand why the copyfrom-rev and copyfrom-path attributes might not be getting copied (due to the hyphen) into the corresponding copyFromRev attributes.

But I can't see any reason why the kind attribute isn't being set within the Path.

Does anyone have any ideas?

Upvotes: 1

Views: 481

Answers (1)

DaveG
DaveG

Reputation: 484

I need to use a digester.addSetProperties() call to get the copyfrom-path and copyfrom-rev attributes populated:

digester.addSetProperties("*/logentry/paths/path", "copyfrom-path", "copyfrompath");
digester.addSetProperties("*/logentry/paths/path", "copyfrom-rev", "copyfromrev");

However for some reason the kind attribute still isn't being populated.

Upvotes: 1

Related Questions