Delete Attribute in xml file

MrinmayMrinmay Member Posts: 74
Hi Expert,

i have a xml file. the data is like below :

xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <Envelope xmlns="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd&quot; xmlns:edp="http://edavki.durs.si/Documents/Schemas/EDP-Common-1.xsd&quot; xmlns:ds="http://www.w3.org/2000/09/xmldsig#&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd"&gt;
- <edp:Header xmlns:edp="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd"&gt;
- <edp:taxpayer>
<edp:taxNumber>77777777</edp:taxNumber>
<edp:taxpayerType>PO</edp:taxpayerType>
<edp:name>CRONUS International Ltd.</edp:name>
<edp:address1>5 The Ring</edp:address1>
<edp:address2>Westminster</edp:address2>
<edp:city>London</edp:city>
<edp:postNumber>1</edp:postNumber>
<edp:postName>London</edp:postName>
<edp:maticnaStevilka />
<edp:resident>true</edp:resident>
</edp:taxpayer>
<edp:responseTo />
<edp:domain />
</edp:Header>
<edp:Signatures xmlns:edp="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd&quot; />
- <body>
<edp:bodyContent xmlns:edp="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd&quot; />
- <DDV-O>
...............
.............

Now i want to delete the attribute in element <EDP:Header>(Bold portion). means i want to modify
<edp:Header xmlns:edp="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd"&gt; to <edp:Header> only.
i am using Automation.

Please help me to remove the attibute & let me know how to do it?

Thanx in advance.

Regards,
Mrinmay

Comments

  • kinekine Member Posts: 12,562
    I am sure that you can use the XSLT to do that (transformation). But how, I do not know, but there are examples on web how to remove namespaces form the XML through the XSLT. May be you will be able to modify it to remove only the one attribute you need.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • pduckpduck Member Posts: 147
    If I remember rightly, you cannot delete elements / attributes inside a DOM document with the DOM methods using Navision Automation. You need to create a second DOM document and copy your XML structure without the attribute which you want to delete. Or use the xsd transformation.
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • MrinmayMrinmay Member Posts: 74
    kine wrote:
    I am sure that you can use the XSLT to do that (transformation). But how, I do not know, but there are examples on web how to remove namespaces form the XML through the XSLT. May be you will be able to modify it to remove only the one attribute you need.

    Hi Kine,

    Thank you for your reply. Can you please let me know how to do it with xslt? Is there any document which i can refer?
    because i am not getting how to use xslt in Nav using automation.

    Regards,
    Mrinmay
  • pduckpduck Member Posts: 147
    Hi, sorry I have not found any code for this anymore. Check this http://www.w3.org/DOM/faq.html at topic "How do I move a Node from one document to another?". You can use the importNode or (with Dom v3) the adoptNode to copy the relevant Nodes from you source XML in a new XML document.

    You schould also try the removeAttributeNode method before. Maybe it works?!

    On the other hand, if copying is the only solution and you don't want to waste time any more then keep it simple. Open the xml File as Textfile, search for the unwanted string xmlns:edp="http://edavki.durs.si/Documents/Schemas/DDV_O_7.xsd&quot;, delete it and replace the original file.

    Maybe, I didn't tried it, you can do this manipulation inside a stream and then load the stream directly inside you XML document without the need to save it before on disk.
  • vaprogvaprog Member Posts: 1,139
    Please have a look at Codeunit 403 Application Launch Management, Function LaunchApp, to see an example of how to do it programmatically from NAV.
Sign In or Register to comment.