Read XML File using Codeunit

julkifli33julkifli33 Member Posts: 1,092
edited 2013-01-31 in NAV Three Tier
Hi All,
is there a way to read XML file using codeunit ?
lets say like this simple file
thanks
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Data>
  <Ledger>
    <ItemNo>PO-000001</ItemNo>
    <Qty>CR-0001</Qty>
  </Ledger>
  <Ledger>
    <ItemNo>PO-000001</ItemNo>
    <Qty>CR-0003</Qty>
  </Ledger>
  <Ledger>
    <ItemNo>PO-000001</ItemNo>
    <Qty>CR-0002</Qty>
  </Ledger>
  <Ledger>
    <ItemNo>PO-000001</ItemNo>
    <Qty>CR-0003</Qty>
  </Ledger>
</Data>

Comments

  • kinekine Member Posts: 12,562
    It is not problem (of course, I do not know why you do not want to use XMLPort...) -you can use DotNet assembly to read xml like from c#...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • julkifli33julkifli33 Member Posts: 1,092
    i need to publish via codeunit
    and do some coding inside codeunit
    so I thought it's better just use 1 object

    and XML port we cant import data using fixed path
    (correct me if i'm wrong... user must browse first)
  • ara3nara3n Member Posts: 9,256
    user doesn't need to specify the path. you can open the file through code and pass the stream to the xmlport.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • julkifli33julkifli33 Member Posts: 1,092
    how to set that?
    i already fill the default name file
    but still need to browse before import
  • kinekine Member Posts: 12,562
    If you want to import this XML as part of some webservice call, you can use XMLPort as parameter in the codeunit function and publish this codeunit. The xmlport will "define" the structure of the parameter (but I am not sure if you will be able to create the exact structure you need)

    Another way is to use BigText parameter, into which the XML is passed as value and you can than stream the text into XMLPort or DotNet assembly.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • julkifli33julkifli33 Member Posts: 1,092
    kine wrote:
    If you want to import this XML as part of some webservice call, you can use XMLPort as parameter in the codeunit function and publish this codeunit. The xmlport will "define" the structure of the parameter (but I am not sure if you will be able to create the exact structure you need)

    Another way is to use BigText parameter, into which the XML is passed as value and you can than stream the text into XMLPort or DotNet assembly.

    so what you mean is like this
    lets say i have 1 function named ImportData
    give this function 1 parameter
    and then from webservice i should call this function including the parameter
    example --> ImportData(Test.xml)

    is it like this?
  • kinekine Member Posts: 12,562
    If I understand your code, no. It will pass the file name. Or if the paramter will be the xml itself, than yes, what you will pass will end in the parameter in NAV.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • julkifli33julkifli33 Member Posts: 1,092
    hi now i can read XML data
    now the problem is...
    previously i use nav 2009 to develop this codeunit
    after i export this object, and then i move it to my 2013 database
    (the same computer)

    there is an error message :
    You cannot create an Automation object "xmldomDoc" on Microsoft Dynamics NAV Server. You must create it on a client computer.


    i have variable name xmldomDoc
    Data type : Automation
    Sub type : 'Microsoft XML, v6.0'.DOMDocument

    anything wrong? or something i must set up first
  • kinekine Member Posts: 12,562
    Automations could be used only client side on NAV 2013. You need to use DotNet Assembly instead.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • julkifli33julkifli33 Member Posts: 1,092
    kine wrote:
    Automations could be used only client side on NAV 2013. You need to use DotNet Assembly instead.
    any clue about dotnet assembly?
    example perhaps
  • kinekine Member Posts: 12,562
    You can start here: http://msdn.microsoft.com/en-us/library/gg502499.aspx

    There is assembly System.Xml.XmlDocument
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • julkifli33julkifli33 Member Posts: 1,092
    kine wrote:
    You can start here: http://msdn.microsoft.com/en-us/library/gg502499.aspx

    There is assembly System.Xml.XmlDocument
    thanks kine
  • julkifli33julkifli33 Member Posts: 1,092
    kine wrote:
    You can start here: http://msdn.microsoft.com/en-us/library/gg502499.aspx

    There is assembly System.Xml.XmlDocument

    anyway any sample for this thing?
  • kinekine Member Posts: 12,562
  • julkifli33julkifli33 Member Posts: 1,092
    kine wrote:
    waaaaaaaa Kine... thank you very much !!
    this is what i need it !
    Thanks! :thumbsup:
Sign In or Register to comment.