XMLPort - Accessing child elements dynamically
halcyon1234
Member Posts: 8
I have an XMLPort (import). One of the elements is a Record, and there's several Elements underneath that line up with the fields (ie: Order Header::"Bill to Name")
Each element also has sub elements that contain information about how the XML Port should behave, which are supplied dynamically by the sender of the XML. Example:

I'm trying to figure out how to dynamically access those sub-elements. My first thought was in marketplace_order::OnBeforeInsertRecord, I might be able to access them. However, the only way I've been able to do this so far is to assign the value to a string DataSource (such as Additional_info1 in the screenshot).
This isn't really feasible, since there are hundreds of nodes, and I need to do them dynamically.
Ideally, there'd be something like
"for each element directly under marketplace_info ...... find node with name "error" ..... if that element has a value, stop XML port and throw up a message with value"
...
The only other thing I can think of is for every single elemtn (document_type, no in the example)-- in OnAfterAssignField or OnAfterAssignVariable , call a function-- "DoCommonThing()"-- it would require pasting DoCommonThing into every OnAfterAssignField / OnAfterAssignVariable
It also occurs to me that an XMLPort, which structurally sound, might not be the right tool for what I'm looking to do?
Each element also has sub elements that contain information about how the XML Port should behave, which are supplied dynamically by the sender of the XML. Example:

I'm trying to figure out how to dynamically access those sub-elements. My first thought was in marketplace_order::OnBeforeInsertRecord, I might be able to access them. However, the only way I've been able to do this so far is to assign the value to a string DataSource (such as Additional_info1 in the screenshot).
This isn't really feasible, since there are hundreds of nodes, and I need to do them dynamically.
Ideally, there'd be something like
"for each element directly under marketplace_info ...... find node with name "error" ..... if that element has a value, stop XML port and throw up a message with value"
...
The only other thing I can think of is for every single elemtn (document_type, no in the example)-- in OnAfterAssignField or OnAfterAssignVariable , call a function-- "DoCommonThing()"-- it would require pasting DoCommonThing into every OnAfterAssignField / OnAfterAssignVariable
It also occurs to me that an XMLPort, which structurally sound, might not be the right tool for what I'm looking to do?
0
Comments
-
I think the XMLPort is not the best choice to do that.
I would try to pre-load the file in OnPreXMLport into a DotNET XML Variable (or XMLDOMDocument object if it is supposed to work in Classic Client, then use a XPath search expression to find a list of nodes including some specific text (error?), or element names, if found then throw an error, or iterate through returned node list and do whatever else needs to be done.
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Slawek: I'm going to go that route. In OnPreXMLPort, would you suggest I use the XMLDoc to .Load(currXMLport.FILENAME), or is there a better / safer way to access the XML Document that the port is using?0
-
I could possibly see two other ways:
One way is like you suggested - to include a bit of the code on every node in OnAfterAssignField or OnAfterAssignVariable, call some function on it checking for errors.
Another way would be to build a custom buffer table where additional field/error handling data could be stored, base the XMLport on that table, and the in OnInsert open make a copy of the record into a Record Ref variable (using REcref.GETTABLE(buffer) ) and then loop through its fields looking for error codes in there.
If you build the buffer in some specific way, like keeping additional information fields next to each other you could do simple FOR based loop iterating through fields of your interest, and after successful check do a TRANSFERFIELDS to your real destination.
XPath based search is nice as you don't have to worry that much about the structure - you can build your XPath search expression to find nodes of your interest in any part of the XML structure.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
