xpath - Store Current XML Element Name using MOXy or JAXB -
i using combination of stax , moxy parse xml files. when parser detects @ specified element, using xpaths, unmarshal element. xpath can represent multiple xml elements. here example:
/a/b/*[self::c or self::d or self::e] in example these paths valid:
/a/b/c /a/b/d /a/b/e in 1 of pojos want store xml element name in string variable, have not had luck far. moxy annotation @xmlvariablenode close want, don't have parent object , don't want one. have tried using moxy annotation @xmlpath, seems moxy doesn't support xpath functions name() or local-name(). here simple example of last attempt:
pojo
public class data extends dataobject { private string source; public string getsource() { return source; } @xmlpath("./name()") public void setsource(string source) { this.source = source; } } unmarshaller:
protected dataobject unmarshallelement(class<? extends dataobject> marshallingclass) throws jaxbexception { dataobject retval = null; if(marshallingclass != null) { unmarshaller jaxbunmarshaller = jaxbunmarshallermapping.get(marshallingclass); if(jaxbunmarshaller != null) { jaxbelement<? extends dataobject> dataobject = jaxbunmarshaller.unmarshal(xmlstreamreader, marshallingclass); retval = dataobject.getvalue(); } else throw new illegalargumentexception("no unmarshaller found " + marshallingclass.getname()); } else throw new illegalargumentexception("no object class provided"); return retval; } i sure ugly in unmarshaller below, don't want to.
jaxbelement<? extends dataobject> dataobject = jaxbunmarshaller.unmarshal(xmlstreamreader, marshallingclass); retval = dataobject.getvalue(); if(dataobject instanceof someclass) retval.setsource(dataobject.getname().getlocalpart()); is possible store current elements name in variable using moxy or jaxb in general?
Comments
Post a Comment