Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How i can generate this XML structure?

Posted on by 570

Good day!

I need generate a xml structure but i ca't delete an attribute, this is my code.

<code>

XmlDocument cfdDocument;
XmlElement Complemento, Leyenda;
cfdDocument = new XmlDocument();

cfdDocument.createElement3("fiscal", "Fiscales", "http://");

Complemento = cfdDocument.createElement3("fiscal", "Fiscales", "http://");

Complemento.setAttribute('version',"1.0");

Leyenda = cfdDocument.createElement3("fiscal", "Leyenda", "http://");

Leyenda.setAttribute('texto',"Description....");
Leyenda.setAttribute('norma',"Norma...");
Leyenda.setAttribute('disposicion',"Disposicion....");

Complemento.appendChild(Leyenda);

</code>

And this is th output  XML

<fiscal:Fiscales version="1.0" xmlns:fiscal="http://">
<fiscal:Leyenda texto="Description...." norma="Norma..." disposicion="Disposicion...." />
</fiscal:Fiscales>

How i can delete this attribute xmlns:fiscal="http://"   ?? y try a string empty  createElement3("fiscal", "Leyenda", "") but it does not work

Thanks in advance.!!!!

*This post is locked for comments

  • ismaelivan Profile Picture
    ismaelivan 570 on at
    RE: How i can generate this XML structure?

    Tks

  • ismaelivan Profile Picture
    ismaelivan 570 on at
    RE: How i can generate this XML structure?

    You're right Martin, I already made it.
    This XML element is inside an XML document, so I didn't need the prefix here, it worked for me to place the same namespace of the main header, they looked like this:

    cfdDocument.createElement3("fiscal", "Fiscales", "http://www.sat.gob.mx/cfd/3");

    <xml>
    <encabezado xmlns:cfdi = "http://www.sat.gob.mx/cfd/3">
    .....
    <fiscal:Fiscales version =" 1.0 ">
    <fiscal:Leyenda texto="Descripción ...." norma="Norma ..." disposicion="Disposición ..." />
    </ fiscal:Fiscales>
    </encabezado>
    </xml>

    Gracias Martin 

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: How i can generate this XML structure?

    Unfortunately your two requirements contradict each other. You can't have a namespace prefix without defining a meaning of this prefix.

    What business problem are you trying to solve by these impossible technical requirements? If the business requirement is meaningful, we should be able to find a suitable technical solution. And if we find that the requirement makes no sense, you'll know that that problem to solve isn't in code...

  • ismaelivan Profile Picture
    ismaelivan 570 on at
    RE: How i can generate this XML structure?

    Good day Martin, tyhanks for your answer.

    But now the output XML is

    <Fiscales version = "1.0">

    <Leyenda texto = "Descripción ...." norma = "Norma ..." disposicion = "Disposición ..." />

    </Fiscales>

    and I want the word fiscal to precede, ex. fiscal:Leyenda fiscal:Fiscal

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: How i can generate this XML structure?

    Using a namespace prefix without actually defining the namespace (which is what you're doing by createElement3("fiscal", "Leyenda", "")) indeed doesn't make sense.

    If you don't want to specify any namespace, use createElement("Leyenda") instead.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans