XML schemaLocation question in codeunit XML DOM export

  • XML schemaLocation question in codeunit XML DOM export

    Posted by DSC Communities on June 1, 2018 at 9:09 am
    • Jason Luchka

      Member

      June 1, 2018 at 9:09 AM

      ?Hi all,
      I’m running into a wall trying to create an XML outstream to meet a vendor’s requirement. I’ve beenĀ slowlyĀ working my way through it, and I’ve almost got it nailed down, but I’m having issues with the schemaLocation attribute.

      Ā Ā Ā  XMLProcessingInst := XMLDOMDocument.CreateProcessingInstruction(‘xml’,’version=”1.0″ encoding=”UTF-8″‘);
      Ā Ā Ā  CurrNode := XMLDOMDocument.AppendChild(XMLProcessingInst);
      Ā Ā Ā  CurrNode := XMLDOMDocument.CreateElement(‘q0′,’RedactedElement’,DocNameSpace);
      Ā Ā Ā  CurrNode := XMLDOMDocument.AppendChild(CurrNode);
      Ā Ā Ā  AddAttribute(CurrNode,’xmlns:q0′,’RedactedWebAddressHere’);
      Ā Ā Ā  AddAttribute(CurrNode,’xmlns:xsi’,’http://www.w3.org/2001/XMLSchema-instance’);
      Ā Ā Ā  AddAttribute(CurrNode,’xsi:schemaLocation‘,’RedactedWebAddressHere Redacted.xsdHere’);

      However, when I execute this code, I get the following output:
      <q0:RedactedElement xmlns:q0=”RedactedWebAddressHere” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” schemaLocation=”RedactedWebAddressHere Redacted.xsdHere”>

      If you look closely, NAV is dropping the “xsi:” that should precede schemaLocation, even though I am passing it to Codeunit 6224 AddAttribute function.

      I’m new to working with namespaces and schemas and all the examples I can find online still use Automation objects instead of DotNet. I suspect it has something to do with the q0 vs xsi prefixs but I don’t know where to go next. Any input or advice is appreciated.

      NAV version is NAV2013.

      ——————————
      Jason Luchka
      Senior Enterprise Applications Analyst
      FFR Merchandising, Inc.
      Twinsburg OH
      ——————————

    • Franz Kalchmair

      Member

      June 1, 2018 at 6:45 PM

      useĀ 
      AddAttributeWithPrefix(CurrNode,’schemaLocation’,’xsi’,’http://www.w3.org/2001/XMLSchema-instance’,’RedactedWebAddress.xsd’);
      instead of
      AddAttribute(CurrNode,’xsi:schemaLocation‘,’RedactedWebAddress.xsd’);

      ——————————
      Franz Kalchmair
      Microsoft MVP
      Senior Consultant
      Austria, Europe
      ——————————
      ——————————————-

    • Jason Luchka

      Member

      June 4, 2018 at 8:37 AM

      ?Franz,
      Thank you. In which object would I find the function you have referenced?

      I do not have a function with the name AddAttributeWithPrefix in codeunit 6224, nor is it available with my system.xml variable.

      ——————————
      Jason Luchka
      Senior Enterprise Applications Analyst
      FFR Merchandising, Inc.
      Twinsburg OH
      ——————————
      ——————————————-

    • Franz Kalchmair

      Member

      June 4, 2018 at 9:31 AM

      i checked with nav 2013 build 46056. in cu 6224 there is a functionĀ AddAttributeWithPrefix in standard nav (cronus db):

      AddAttributeWithPrefix(VAR XMLNode : DotNet “System.Xml.XmlNode”;Name : Text;Prefix : Text;NameSpace : Text;NodeValue : Text) : Integer
      XMLNewAttributeNode := XMLNode.OwnerDocument.CreateAttribute(Prefix,Name,NameSpace);
      EXIT(AddAttributeToNode(XMLNode,XMLNewAttributeNode,NodeValue));

      AddAttributeToNode(VAR XMLNode : DotNet “System.Xml.XmlNode”;VAR XMLNewAttributeNode : DotNet “System.Xml.XmlNode”;NodeValue : Text) ExitStatus : Integer
      IF ISNULL(XMLNewAttributeNode) THEN BEGIN
      Ā  ExitStatus := 60;
      Ā  EXIT(ExitStatus)
      END;
      IF NodeValue <> ” THEN
      Ā  XMLNewAttributeNode.Value := NodeValue;

      XMLNode.Attributes.SetNamedItem(XMLNewAttributeNode);

      ——————————
      Franz Kalchmair
      Microsoft MVP
      Senior Consultant
      Austria, Europe
      ——————————
      ——————————————-

    • Jason Luchka

      Member

      June 4, 2018 at 10:15 AM

      ?Thanks Franz, that would explain it. I am on build 36919.

      ——————————
      Jason Luchka
      Senior Enterprise Applications Analyst
      FFR Merchandising, Inc.
      Twinsburg OH
      ——————————
      ——————————————-

    • Jason Luchka

      Member

      June 4, 2018 at 11:30 AM

      ?Ok – quick follow up.

      I ported over the new functions into my codeunit 6224 and it works perfectly for the attribute in question. It worked so well, it made me realize the other two attributes I added weren’t actually right (they show in red in IE). I am trying to convert my other two attributes to use the new method and running into issues.

      First, here is the initial view of the XML in IE. I’m guessing that because the first and second attributes are highlighted in bold RED that the XML is malformed somehow (even though it “looks” right to the human eye). The third attribute “looks” good.

      Now, if I attempt to use the new AddAttributeWithPrefix function:

      I get the following run-time error:
      Microsoft Dynamics NAV
      ---------------------------

      Break On Error Message:
      Ā 
      This message is for C/AL programmers: A call to System.Xml.XmlDocument.CreateAttribute failed with this message: The namespace declaration attribute has an incorrect 'namespaceURI': 'http://redacted.com'.
      ---------------------------
      OK
      ---------------------------

      It doesn’t matter what value I pass as the NameSpace (empty string included), I get the same error. I’m not clear on what I am suppose to pass here. The rest of the document works just fine with the DocNameSpace value I’m passing into the FFRAddAttributeWithPrefix function. Any other insight you can provide is appreciated. Thank you!

      ——————————
      Jason Luchka
      Senior Enterprise Applications Analyst
      FFR Merchandising, Inc.
      Twinsburg OH
      ——————————
      ——————————————-

    DSC Communities replied 7 years, 3 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘XML schemaLocation question in codeunit XML DOM export’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!