c# - Adding a new node as a child is automatically adding the xmlns attribute -
i'm trying modify xml document. xml structured this:
<?xml version='1.0' encoding='iso-8859-1'?> <modelo39 xmlns="http://www.dgci.gov.pt/2002/ot" versao="1"> <rosto> <quadroinicio /> <quadro01> <q01c01>555555555</q01c01> </quadro01> <quadro06> <rostoq06t> </rostoq06t> </quadro06> </rosto> </modelo39>
i'm trying add rostoq06t new node this:
<rostoq06t-linha numero="1"> <nif>100000000</nif> <codrend>01</codrend> <rendimento>2500</rendimento> <retido>500</retido> </rostoq06t-linha>
i'm creating new element name rostoq06t-linha , i'm adding node rosto06t:
xmlelement node06t = xmldoc.createelement("rostoq06t-linha"); node06t.setattribute("numero", linha.tostring()); //here add elements node06t xmldoc.documentelement.getelementsbytagname("rostoq06t").item(0).appendchild(node06t);
my problem rosto06t-linha being generated this:
<rostoq06t-linha numero="1" xmlns="">
i can't figure out why it's being added attribute xmlns node, if element child of rostoq06t.
can me fixing this?
because created rostoq06t-linha
element without namespace, ie. empty namespace.
you must use proper createelement
overload
xmlelement node06t = xmldoc.createelement("rostoq06t-linha","http://www.dgci.gov.pt/2002/ot");
unfortunately, have specify full namespace children create!
Comments
Post a Comment