JAXB AND DARN NS2
08/04/2010
If you have to assign a namespace to an xml and that Marshall needs to be done without a declaration of 'xmlns: ns2' is not holy to do the JAXB remove it, I've been searching a lot and because of the rush to solve the problem I found two solutions that do not are best, but solve the problem.
1: Remove the node of the XML parse in ns2:
# Doc.getElementsByTagName NodeList elements = ('infNFe');
# Element el = (Element) elements.item (i);
# El.getAttribute String id = ('id');
# / / Here is the removal of the attribute ...
# Doc.getDocumentElement (). RemoveAttribute ('xmlns: ns2');
# ((Element)
# Doc.getDocumentElement (). GetElementsByTagName ('NFe'.) Item (0))
#. SetAttribute ('xmlns', 'http://www.portalfiscal.inf.br/nfe');
#
# Create a DOM XMLSignatureFactory That Will Be Used to
# Generate the enveloped signature.
#
# Fac.newReference Reference ref = ('#' + id, fac.newDigestMethod (
# DigestMethod.SHA1, null) transformList, null, null);
A full code:
http://www.guj.com.br/posts/list/83758.java
Here is a workaround that was used until it was resolved the way up:
/ / Pass the file to be re-formatted as a string
public void ajustaXml (File file) throws Exception (
zar namespaces, the link:
http://blogs.sun.com/enterprisetechtips/entry/customizing_jaxb
You find the solution.
You need to create a class that extends NamespacePrefixMapper vide:
[Code] NamespacePrefixMapper PreferredMapper f = new ();
marshal (jc, and, m);
public static class extends PreferredMapper NamespacePrefixMapper (
@ Override
getPreferredPrefix public String (String namespaceURI, String suggestion, boolean requirePrefix) (
return 'mappedNamespace' + namespaceURI;
)
) [/ Code]
After you in your Marshaller arrow:
[Code] final Marshaller Marshaller context.createMarshaller = ();
marshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty (Marshaller.JAXB_ENCODING, 'UTF-8');
marshaller.setProperty ('com.sun.xml.internal.bind.namespacePrefixMapper'
NamespacePrefixMapperImpl new ('http://www.isotc211.org/2005/gmd'));[/ code]
Hug
Topo   Link para este post Comentários
Redação Ige. ( redacao@informativogeral.com.br )
VOTE NO AMARELINHO PARA O TOP BLOG 2010




