Or you can pass the XML into XMLDom and just remove the first node and you are done...
Whoa... This is getting over complicated to what was suppose to be an hour of work. I think I'll try to work with the vendor to see if they can accept the delcaration. It's suppose to be XML standard anyway.
I was going to say that it is part of well formed XML and should be accepted by any XML parser. Of course, namespaces are also part of wellformed XML and should also be accepted by XMLPorts, which they aren't...
Or you can pass the XML into XMLDom and just remove the first node and you are done...
We have similar issue, that customers webservice does not accept the first line.
I've port that exports xml file and I'm sending it to the webservice by automation,
You say pass xml into XMLDom, how you remove first node? I'm not sure how to select it,.. this did not work fex:
CREATE(XmlDoc);
XmlDoc.async := FALSE;
XmlDoc.load(Tiedosto); // <-- the xml file
// This does not work???
XmlNode := XmlDoc.selectSingleNode('XML');
XmlDoc.removeChild(XmlNode);
IF ISCLEAR(XmlHttp) THEN
CREATE(XmlHttp);
XmlHttp.open('POST', Url, FALSE);
I didn't want to start new topic as this is quite close to the previous one.
As navision leaves empty element tags on the xml file how those elements could be checked and then removed with xmldom?
I'm sure there is a way to check the elements if their values are not set. This would be very usefull with huge invoices, would save alot file size and bandwidth on transfering the file.
You would have to do it through xmldom. Basically write a generic function that loops through all the children and call it recursively.
You would in the function checked the value of each node and if it's blank, remove the child.
Ahmed Rashed Amini
Independent Consultant/Developer
I have a simular problem (trying to delete the <xml>-tag) but I'm not familuar with using the the XML automation objects. Can someone help me where to put the above sollution in my code.
(using NAV 2009 SP1 classic)
I have a simular problem (trying to delete the <xml>-tag) but I'm not familuar with using the the XML automation objects. Can someone help me where to put the above sollution in my code.
(using NAV 2009 SP1 classic)
I'm not 100% sure but the second code seems okay to me or if the remove child does not work then the problem might be in the process queue.
First the load thingy needs the file or stream of string (xml data) where the remove child selects the first element, first child. then remove child nukes the first tag which is probably the <xml> and last the file exports out.
I hope you get it working. It took me a week to get this done first time
I would try it a little differently than what you have...
VAR
gRecPurchaseHeader : Record 38
XMLDOMDocument : Automation :'Microsoft XML, v6.0'.DOMDocument;
XMLNode : Automation :'Microsoft XML, v6.0'.IXMLDOMNode;
TempBlob : Record 99008535;
OutStreamObj : OutStream;
InStreamObj : InStream;
IF ISCLEAR(XMLDOMDocument) THEN BEGIN
CREATE(XMLDOMDocument);
XMLDOMDocument.async := FALSE;
END;
TempBlob.Blob.CREATEOUTSTREAM(OutStreamObj);
XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
TempBlob.Blob.CREATEINSTREAM(InStreamObj);
XMLDOMDocument.load(InStreamObj);
XMLNode := XMLDOMDocument.firstChild;
XMLDOMDocument.removeChild(XMLNode);
XMLDOMDocument.save('F:\Outbound\PO.xml');
This works, I would probably add some more logic in that would give an error/message if there was nothing to do and maybe parameterize the file name for the save though.
Comments
You need to load the xmlfile after xmlport has been run and remove it through xmldom
Also notice that you are running it in UTF-16
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
What's wrong with UTF-16?
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
What kind of problems can we expect with UTF-16? Is it just general problems in the XML world? Or is it NAV specific?
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
As far as request take a look at this thread.
viewtopic.php?f=23&t=31648&hilit=never+forget
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I don't think XMLport runs any codeunits when writing its output? I also don't find any property settings that removes the declaration line.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
you can pass a blank string to the function processingInstruction. Thus removing it. It doesn't hurt to try it.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Whoa... This is getting over complicated to what was suppose to be an hour of work. I think I'll try to work with the vendor to see if they can accept the delcaration. It's suppose to be XML standard anyway.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
RIS Plus, LLC
We have similar issue, that customers webservice does not accept the first line.
I've port that exports xml file and I'm sending it to the webservice by automation,
You say pass xml into XMLDom, how you remove first node? I'm not sure how to select it,.. this did not work fex:
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Agh stupid me, it was a property #-o
Thanks Kine :thumbsup:
I didn't want to start new topic as this is quite close to the previous one.
As navision leaves empty element tags on the xml file how those elements could be checked and then removed with xmldom?
I'm sure there is a way to check the elements if their values are not set. This would be very usefull with huge invoices, would save alot file size and bandwidth on transfering the file.
You would in the function checked the value of each node and if it's blank, remove the child.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
(using NAV 2009 SP1 classic)
I tried to do the following:
After "XMLfile.CREATEOUTSTREAM(OutStreamObj);" add the code:
What would be the right way to do this?
I'm not 100% sure but the second code seems okay to me or if the remove child does not work then the problem might be in the process queue.
First the load thingy needs the file or stream of string (xml data) where the remove child selects the first element, first child. then remove child nukes the first tag which is probably the <xml> and last the file exports out.
I hope you get it working. It took me a week to get this done first time
http://img543.imageshack.us/i/foutmeldingf.png/
Any ideas?
http://www.interdynbmi.com