XML Export with CDATA or special chars

george175george175 Member Posts: 26
Hello to everybody,
Iam trying to export xml from NAV 2015 to another system with WS. Iam using CU XML DOM Management and I need to replace this:

-<Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; ControllingInstance="TecCom" Version="4.1" Type="Invoice">
<Document/>
-<OrderHeader OrderType="RequestForOffer">
-<OrderIssueDate>
<Date Format="YYYYMMDD">29.02.16</Date>
</OrderIssueDate>
<CustomerInfo DispatchMode="Normal" Name="KS"/>
-<SellerParty>
<PartyNumber Qualifier="BuyerNumber">BUYERNUMBER</PartyNumber>
</SellerParty>
-<BuyerParty>
<PartyNumber Qualifier="SupplierNumber">SUPPLIERNUBBER</PartyNumber>
</BuyerParty>
<Currency>CZK</Currency>
<OrderProcessing/>
</OrderHeader>
-<OrderItem>
<PositionNumber>1</PositionNumber>
-<RequestedQuantity>
<Quantity>1</Quantity>
</RequestedQuantity>
-<ProductId>
<MakerCode>*</MakerCode>
<ProductNumber>50007543</ProductNumber>
<ProductName>zdvihátko vent.1,5dCi/7,70mm</ProductName>
</ProductId>
<ProductDescription/>
<ItemProcessing/>
</OrderItem>
-<OrderItem>
<PositionNumber>1</PositionNumber>
-<RequestedQuantity>
<Quantity>1</Quantity>
</RequestedQuantity>
-<ProductId>
<MakerCode>*</MakerCode>
<ProductNumber>50007544</ProductNumber>
<ProductName>zdvihátko vent.1,5dCi/7,75mm</ProductName>
</ProductId>
<ProductDescription/>
<ItemProcessing/>
</OrderItem>
</Order>



into this :


&lt;Order xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt; ;
&lt;Document Type=&quot;Invoice&quot; Version=&quot;4.1&quot; ControllingInstance=&quot;TecCom&quot;/&gt;
&lt;OrderHeader OrderType=&quot;RequestForOffer&quot;&gt;
&lt;OrderIssueDate&gt;
&lt;Date Format=&quot;YYYYMMDD&quot;&gt;20160225&lt;/Date&gt;
&lt;/OrderIssueDate&gt;
&lt;CustomerInfo Name=&quot;KS&quot;/&gt;
&lt;SellerParty&gt;
&lt;PartyNumber Qualifier=&quot;BuyerNumber&quot;&gt;7&lt;/PartyNumber&gt;
&lt;/SellerParty&gt;
&lt;BuyerParty&gt;
&lt;PartyNumber Qualifier=&quot;SupplierNumber&quot;&gt;615016&lt;/PartyNumber&gt;
&lt;/BuyerParty&gt;
&lt;Currency&gt;CZK&lt;/Currency&gt;
&lt;OrderProcessing DispatchMode=&quot;Normal&quot;/&gt;
&lt;/OrderHeader&gt;
&lt;OrderItem&gt;
&lt;PositionNumber&gt;1&lt;/PositionNumber&gt;
&lt;RequestedQuantity&gt;
&lt;Quantity&gt;26&lt;/Quantity&gt;
&lt;/RequestedQuantity&gt;
&lt;ProductId&gt;
&lt;MakerCode&gt;*&lt;/MakerCode&gt;
&lt;ProductNumber&gt;50007544&lt;/ProductNumber&gt;
&lt;/ProductId&gt;
&lt;ProductDescription&gt;
&lt;ProductName&gt;desc&lt;/ProductName&gt;
&lt;/ProductDescription&gt;
&lt;ItemProcessing/&gt;
&lt;/OrderItem&gt;
&lt;/Order&gt;

I know , that i have to use cdata or special chars strings, but dont know, how to do it. Is here some possibility to use 'Microsoft XML, v6.0'.IXMLDOMCDATASection or somethig else ???



Thank's to everybody.

George

Answers

  • lubostlubost Member Posts: 627
    Hi,

    I think that you don't need CDATA. < is the same as < and so on. You can create XML by XMLPort directly and you should play with date format, because in the first XML isn't your date formatted accordingly to needed format.
  • Remco_ReinkingRemco_Reinking Member Posts: 74
    Hi George,

    You could use XMLExcape for this:
    LongTxt := TheXMLDoc.InnerXml;
    LongTxt := XMLEscaper( LongTxt);
    

    Where
    TheXMLDoc is a dotnet variable of type: System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    and LongTxt is a text variable without length restriction
    XMLEscaper is a function:
    LOCAL XMLEscaper(InputTxt : Text) ResultTxt : Text
    EXIT( Escape.Escape(InputTxt));
    

    Where Escape is a dotnet variable of type: System.Security.SecurityElement.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
  • george175george175 Member Posts: 26
    edited 2016-03-01
    lubost wrote: »
    Hi,

    I think that you don't need CDATA. < is the same as < and so on. You can create XML by XMLPort directly and you should play with date format, because in the first XML isn't your date formatted accordingly to needed format.

    Yes, you are right, but this was just peace of xml. Whole XML is 3 nested xml into one xml:
    first one has <element>,
    second one - "& l t;ParameterData> & # 1 3 ;"
    and last one - "& a m p;lt;/SellerParty&g t;& # 1 3 ;"


    -
    " - & q u ot;
    ' - & a p os;
    < - & l t;
    > - & g t;
    & - & a m p;

    george
  • george175george175 Member Posts: 26
    edited 2016-03-01
    Hi George,

    You could use XMLExcape for this:
    LongTxt := TheXMLDoc.InnerXml;
    LongTxt := XMLEscaper( LongTxt);
    

    Where
    TheXMLDoc is a dotnet variable of type: System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    and LongTxt is a text variable without length restriction
    XMLEscaper is a function:
    LOCAL XMLEscaper(InputTxt : Text) ResultTxt : Text
    EXIT( Escape.Escape(InputTxt));
    

    Where Escape is a dotnet variable of type: System.Security.SecurityElement.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'



    So if i will have LongTxt ='<PartyNumber Qualifier="SupplierNumber">SUPPLIERNUBBER</PartyNumber>'

    how can I save it into xml with function addElement in NAV? or which another way i have to use it ?
    (NewChildNode := XMLNode.OwnerDocument.CreateNode('element',NodeName,NameSpace);
    - XMLNode.AppendChild(NewChildNode))


    thx for answer
  • Remco_ReinkingRemco_Reinking Member Posts: 74
    Sample usage:
    procedure InsertXMLDocAsElement(TagName : Text;TheXMLDoc : DotNet "System.Xml.XmlDocument")
    LongTxt := TheXMLDoc.InnerXml;
    LongTxt := XMLEscaper( LongTxt);
    IF TagName <> '' THEN
      Add_Element( TagName, LongTxt,FALSE)
    ELSE
      ERROR('Programming error.');
    

    With Add_Element function defined as:
    procedure Add_Element(ElemTagName : Text;ElemTagValue : Text;OptionalField : Boolean)
    IF OptionalField AND (ElemTagValue='') THEN
      EXIT;
    
    XMLDOMMgt.AddElementWithPrefix( EnvelopeXmlNode, ElemTagName, ElemTagValue, CurrentPrefix, CurrentNameSpace, CreatedXmlNode);
    
  • george175george175 Member Posts: 26
    Sample usage:
    procedure InsertXMLDocAsElement(TagName : Text;TheXMLDoc : DotNet "System.Xml.XmlDocument")
    LongTxt := TheXMLDoc.InnerXml;
    LongTxt := XMLEscaper( LongTxt);
    IF TagName <> '' THEN
      Add_Element( TagName, LongTxt,FALSE)
    ELSE
      ERROR('Programming error.');
    

    With Add_Element function defined as:
    procedure Add_Element(ElemTagName : Text;ElemTagValue : Text;OptionalField : Boolean)
    IF OptionalField AND (ElemTagValue='') THEN
      EXIT;
    
    XMLDOMMgt.AddElementWithPrefix( EnvelopeXmlNode, ElemTagName, ElemTagValue, CurrentPrefix, CurrentNameSpace, CreatedXmlNode);
    



    please and do you know how to change this <?xml version="1.0"> into this:
    <?xml version="1.0" encoding="UTF-8"?>
Sign In or Register to comment.