1

I need set a namespace in a child and in its child too, but, when I attribute the same namespace, the sub child comes with no namespace.

I need something like that:

<?xml version="1.0" encoding="UTF-8"?>
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
    <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
        <infNFe versao="2.00" Id="NFe35120810609770000190550010000011151000011155">
            ...

But my code is generating only this:

<?xml version="1.0" encoding="UTF-8"?>
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
    <NFe>
        <infNFe versao="2.00" Id="NFe35120810609770000190550010000011151000011155">
            ...

The code that generates this part of the XML is:

Document doc = new Document();
Namespace portal = Namespace.getNamespace( "http://www.portalfiscal.inf.br/nfe" );

Element tagNfeProc = new Element( "nfeProc", portal );
tagNfeProc.setAttribute( "versao", "2.00" );

Element tagNFe = new Element( "NFe", portal );

...

tagNfeProc.getChildren().add( tagNFe );

doc.setRootElement( tagNfeProc );
teukkam
  • 4,267
  • 1
  • 26
  • 35
  • Have you tried to simply use: tagNFe.setAttribute("xmlns","http://www.portalfiscal.inf.br/nfe")? – drewich May 05 '13 at 22:24

1 Answers1

0

If you really want to add it, you have to do it manually, use the 'setAttribute' method mentioned before me.

Otherwise:
The 'NFe' tag doesn't require the namespace attribute again, because that namespace is already declared on a higher level (top level in your example), and it will be used (inherited) within the entire block just where you declared it.

After a little search, a brief description about XML namespaces :)

Community
  • 1
  • 1
Syry
  • 13
  • 4