Creating an XMLObject
Brent Putman
putmanb at georgetown.edu
Mon Oct 5 13:24:42 EDT 2015
>
>
> >
> > static XMLObject
> unmarshallFromInputStream(net.shibboleth.utilities.java.support.xml.ParserPool,
> InputStream)
> >
> > But I'm not sure whether this is the right method
>
>
Assuming that's from XMLObjectSupport, either that one or the other one
that takes a Reader (XMLObjectSupport. unmarshallFromReader( ... )), as
you already found below, are going to be the simplest way.
Essentially the steps are: 1) parse the input source to a DOM Document
2) unmarshall the Document's root element
(Document#getDocumentElement()) into an XMLObject.
That basic process never really changes. Those 2 XMLObjectSupport
methods are just helpful utility methods that hide the details of all
that, handle error conditions, etc.
On 10/5/15 12:59 PM, Camel Guy wrote:
>
> XMLObjectSupport. unmarshallFromReader( ... )
>
> Passing a BasicParserPool and a StringReader wrapping a string that
> contains XML, I get:
>
> 2015-10-05 09:50:29,884 - ERROR
> [org.opensaml.core.xml.util.XMLObjectSupport:213] - Unable to
> unmarshall Reader, no unmarshaller registered for element attributes
>
Yeah, I don't know what the error is based on that. The line number
and log text there don't match up with the latest trunk. Exactly what
version of the IdP are you running here?
> I need to parse XML, not unmarshal binary goo, so XMLObjectSupport
> appears to be a dead end.
>
It's not, it's exactly what you need. At least the simplest way.
You need to clarify what your "XML" is. In general that's not a
meaningful description. You probably mean a String serialization of an
XML structure, and so a Reader or InputStream is exactly what you need
there. It's not binary goo. If you were doing this with plain old
Java and JAXP, you'd still need to parse that "XML" into a DOM
Document. It's no different here.
Would also be helpful to know where/how you're getting this XML
(reading from a file? building yourself on-the-fly?). And what it
actually looks like (the content). If it's not a type supported by the
existing XMLObject providers registered in the system for known
schemas, then you'll need to understand how to work with the structure
you get back - probably an XSAny instance, which is sort of a generic
type able to represent any content model.
Re: reading/parsing an some XML serialization: if you are currently
building this on the fly, it might be simpler to actually just build
the XMLObject in your code, as opposed to trying to parse something
unnecessarily, like building up a String and then parsing it (although
the latter is perfectly possibly, just inefficient - both
performance-wise and developer-wise).
--Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/users/attachments/20151005/3dc6df43/attachment.html>
More information about the users
mailing list