Return Propreties from XML Node

David_CoxDavid_Cox Member Posts: 509
Hi,
I have a codeunit that is reading an XML file, I am returning a list of nested nodes called "Item", I cannot work out how to return the "ID" of each node.

Part of Nested XML:
<Item>
  <Properties>
    <ID>1</ID>
    <Name>"Item 1"</Name>
  </Properties>
</Item>
<Item>
  <Properties>
    <ID>4</ID>
     <Name>"Item 4"</Name>
  </Properties>
</Item>
<Item>
  <Properties>
    <ID>5</ID>
     <Name>None</Name>
  </Properties>
</Item>

In CAL code I can return and loop throught the list showing the text and get:
1"Item 1"
4"Item 4"
5None
//Load our XML into a XML Doc
CREATE(XMLDoc);
XMLDoc.load(FileName);

//Gets a list of Items to loop through
XMLNodeList := XMLDoc.selectNodes('//Item');
FOR Counter := 1 TO XMLNodeList.length DO BEGIN
  XMLNode := XMLNodeList.item(Counter-1);
  Message('%1',XMLNode.text());
END;

I have tried all sorts to return the "ID" of the node from the list, but it returns an ID from another node at the start of the file?

Any Help Apperciated!

David
Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com

Comments

  • ara3nara3n Member Posts: 9,256
    need more info on the xml structure on where it is returning the ID from.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • David_CoxDavid_Cox Member Posts: 509
    Hi Rashed,
    I am working on a bit of code for form and page field level security, so we can make form and page fields and controls VISIBLE and EDITABLE based on a template and assigned user and codeunit calls.

    It is quite common for a company to want some users to be able to view but not edit specific fields, telesales person create an order but not view,edit or action some controls, same form line manager can do everything, we can use role centres and create different menus, but if it is to limit a few controls for a few users it can be expensive.

    To deal with the form and page CAL code I am exporting the page or form object as xml, then listing the controls, creating the code blocks to add to the pages and forms.

    This is not for a customer just something I have been wanting to do, I have had several different ways of doing this before, and learnt as I went along, so I thought it would make a module and as I am a bit light on XML skills :oops: , I can look at XML process at the same time.

    If you export form4 and page4, you will see in a page4.xml the controls are <Field>, in a form4.xml they are <Control> with a <ControlType>

    I am working with Version 2009 R2

    Regards

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • ara3nara3n Member Posts: 9,256
    Is there a reason you need to add the code to form/pages?

    There are triggers in CU that you can use to see which field the user has modified and error out.

    Also Export to XML is not supported in 2013.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • David_CoxDavid_Cox Member Posts: 509
    Hi Rashed,
    I am looking at form and not table level, I can stop the changing of a field at table level using RecRef and FieldRef, sending rec and xrec, I have done this before in th on modify trigger, what this cannot do is hide or disable a field on a form or page.

    Why Microsoft would introduce a nice function
    EXPORTOBJECTS(FileName, ObjectTableRecord[, Format])
    
    in one version and deprecate it in the next is not consistant.

    In 2009 they introduced EXPORTOBJECTS for exporting and importing Objects as XML, so any work done around this by resellers to add value to their business, is now just lost time, money and deprecated code. :-k

    This was a great function as objects could be exported and imported in CAL Code, rather than having to do this from the object designer, one simple use that comes to mind while developing is tracking changed objects, initial code could loop through the objects and store a base version, then daily loop through and save any changed objects as a restore point.

    I will have to re-think the XML side of things, objects can be exported in
    Dynamics NAV 2013 as text files or fobs but not XML.

    It was only a play project, I had already done a simple version for a customer to generate code by reading a form exported as *.txt, reading the file and making the code to copy and paste.


    Thanks anyway!

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
Sign In or Register to comment.