XMLPort - starter help

jversusjjversusj Member Posts: 489
i have never worked with XML files before. The system i am working in has 3.7 objects sitting on a 5.0 executable. I was recently tasked with getting a cXML document being transmitted by our customer to import into NAV. We bought the XMLPort granule for our license and I read the XMLPort section of the application designers guide.

I have some questions that i could not find answers for already on this forum.

I get the impression that XMLPorts only work when you are processing XML files that always follow the same format, and that you must explicitly list each and every element and attribute that are to be encountered. Is this correct? If so, how are people handling XML documents that have dynamic formats?

Perhaps it is better if i give a generalized and simplified example.

sometimes i can get an order where the ship-to elements look like this:
<xml>
     <customer>
          <shipto>
               <deliverto>the store</deliverto>
               <deliverto>home furnishings department</deliverto>
               <deliverto>Jan Smith</deliverto>
               <street>123 Street</street>
               <city>Any Town</city>
          </shipto>
     </customer>
</xml>

other times i may receive a file like this:
<xml>
     <customer>
          <shipto>
               <deliverto>the store</deliverto>                        
               <street>ABC street</street>
               <city>Any Town</city>
          </shipto>
     </customer>
</xml>

the amount of info included is up to the customer creating the PO on their end. they can add optional values if they want to. they have nothing forcing them to use a certain format.

what would i do in my XMLPort to make this work?

Further, they keep using an element called "Extrinsic" over and over again, and it can pop up for an address or not at all, or pop up on an item or not at all. Is it unusual that the cXML file i receive makes use of the same element names over and over again and different levels of indentation? for example, Credential shows up 5 times, and each Credential has a domain attribute that goes with it. My NAV doesn't need any of this data, but i have to tell it is there, correct? so i have a ton of text variables with ugly names like Credential1 thru Credential5, for example.
kind of fell into this...

Comments

  • SavatageSavatage Member Posts: 7,142
  • ara3nara3n Member Posts: 9,256
    As far as optional elements, there is a property called MinOccurs, Set it to zero.

    As far as repeated elements, the way you are doing it is fine.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • jversusjjversusj Member Posts: 489
    Savatage wrote:
    Maybe these can help

    Xml Import Sample
    viewtopic.php?f=7&t=2266
    Xml Export
    viewtopic.php?f=7&t=1775
    i looked at the import sample, but it confused me more. I am frankly not equipped to process that file in the fashion suggested there. I don't understand how to call the automation objects and i don't understand the syntax, that's why i hoped i could make use of the XMLPort. I thought I could just line up my elements and be done with it. then i discovered the file i'm expecting could change like the wind.

    for this minoccurs=0 angle, how do i know the element should even exist, if the customer can just add stuff whereever they want? do i add 10 deliverto elements and set the minoccurs to 0, just to be sure i can handle whatever they send?

    i'm so confused!
    kind of fell into this...
  • jversusjjversusj Member Posts: 489
    bottom line, do i have to have every potential element listed in the XML port, or will NAV just ignore whatever i do not include?

    Most of the data contained in the file i am receiving is extraneous and is not needed in NAV.

    any help or sugguestions are greatly appreciated!
    kind of fell into this...
  • DenSterDenSter Member Posts: 8,305
    jversusj wrote:
    bottom line, do i have to have every potential element listed in the XML port, or will NAV just ignore whatever i do not include?
    Yes. You can use the MinOccurs property as Rashed suggested in case of optional elements
    jversusj wrote:
    Most of the data contained in the file i am receiving is extraneous and is not needed in NAV.
    You can tie an element to a dummy variable, and manage what the XMLPort does with it elsewhere.
  • jversusjjversusj Member Posts: 489
    DenSter wrote:
    Yes. You can use the MinOccurs property as Rashed suggested in case of optional elements

    thanks!
    yikes! how would i handle an optional element called Extrinsic that has any number of attributes and values? would i set the min occurs to zero for extrinsic and for its attribute? how would i read the differing attributes and know where to put them in NAV?

    example:
    <extrinsic name="TAXABLE">N</extrinsic>
    <extrinsic name="account code">1469200</extrinsic> //this is the buyers internal commodity code for the good which I have no use for
    <extrinsic name="LINEORIGIN">Catalog</extrinsic>
    

    these are optional fields that can be added or omitted by the buyer. how would i set up the xmlport to handle this?
    kind of fell into this...
  • DenSterDenSter Member Posts: 8,305
    Ah that is an attribute that belongs to an element. Off the top of my head, you create a line in the XMLPort for an element called 'extrinsic', and indented underneath it you create lines for all possible attributes, each one with its proper minoccurs and maxoccurs property. I don't exactly know how it would behave, you'll have to play around with it. I would think you can put the attribute values into global variables that you can then evaluate and process in a dataitem trigger of the extrinsic element.

    Check out XMLPort 8610 for an example with an attribute.
  • jversusjjversusj Member Posts: 489
    thank you!
    i have been trying to get a complete list of the possible attributes from the buyer but that has not been forthcoming. I am happy to know that i have not been mistaken in requesting this information. if i can get a list from them, i should be in much better shape to handle this.

    thanks again to everyone.

    i won't mark this solved just yet...
    kind of fell into this...
Sign In or Register to comment.