Created
December 27, 2010 16:00
-
-
Save jawher/756241 to your computer and use it in GitHub Desktop.
Immanix sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<root> | |
<entry> | |
<value>[...]</value> | |
</entry> | |
<entry> | |
<value>[...]</value> | |
<extra>[...]</extra> | |
</entry> | |
<entry> | |
<value>[...]</value> | |
</entry> | |
: | |
: | |
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StaxMatcher<String> value = start("value").thenr(chars()).thenl(end("value")); | |
StaxMatcher<String> extra = start("extra").thenr(chars()).thenl(end("extra")); | |
StaxMatcher<Tuple2<String, String>> entry = start("entry").thenr(value).then(extra).thenl(end("entry")); | |
Mapper<Void> execEntry = new Mapper<Tuple2<String, String>, T>(entry) { | |
public Void process(Tuple2<String, String> data) { | |
// insert data into the database | |
return null; | |
} | |
} | |
StaxMatcher<Void> entries = execEntry.zeroOrMore(); | |
StaxMatcher<Void> almighty = startDoc().then(start("root")).thenr(entries).thenl(end("root")).thenl(endDoc()); | |
XMLInputFactory inputFactory = createInputFactory(); | |
XMLEventReader evr = inputFactory.createXMLEventReader(new FileInputStream("/some/file.xml")); | |
MatcherResult<Void> result = almighty.match(evr); | |
if(result.isFailure()){ | |
//handle errors | |
} else { | |
//everything went well | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment