XMLPort for this XML File...

ebsoftebsoft Member Posts: 81
Hi everybody,
can you help me creating an XMLPort object based on this XML File?

I have already created the NAV Table in which the data goes on.

Here is the table:
Enabled	Field No.	Field Name	Data Type	Length	Description
Yes	1	Data	Code	10	
Yes	2	Mercato	Code	10	
Yes	3	Ora	Integer		
Yes	4	PUN	Decimal		
Yes	5	Nord	Decimal		

And here is the XML File (I've already removed namespace):
  <?xml version="1.0" encoding="UTF-8" ?> 
 <NewDataSet>
   <schema id="NewDataSet">
     <element name="NewDataSet" IsDataSet="true" UseCurrentLocale="true">
       <complexType>
         <choice minOccurs="0" maxOccurs="unbounded">
           <element name="Prezzi">
             <complexType>
               <sequence>
                 <element name="Data" type="xs:string" minOccurs="0" /> 
                 <element name="Mercato" type="xs:string" minOccurs="0" /> 
                 <element name="Ora" type="xs:string" minOccurs="0" /> 
                 <element name="PUN" type="xs:string" minOccurs="0" /> 
                 <element name="NAT" type="xs:string" minOccurs="0" /> 
                 <element name="CALB" type="xs:string" minOccurs="0" /> 
                 <element name="CNOR" type="xs:string" minOccurs="0" /> 
                 <element name="CSUD" type="xs:string" minOccurs="0" /> 
                 <element name="NORD" type="xs:string" minOccurs="0" /> 
                 <element name="SARD" type="xs:string" minOccurs="0" /> 
                 <element name="SICI" type="xs:string" minOccurs="0" /> 
                 <element name="SUD" type="xs:string" minOccurs="0" /> 
                 <element name="AUST" type="xs:string" minOccurs="0" /> 
                 <element name="BRNN" type="xs:string" minOccurs="0" /> 
                 <element name="COAC" type="xs:string" minOccurs="0" /> 
                 <element name="CORS" type="xs:string" minOccurs="0" /> 
                 <element name="E_CO" type="xs:string" minOccurs="0" /> 
                 <element name="E_NE" type="xs:string" minOccurs="0" /> 
                 <element name="E_NW" type="xs:string" minOccurs="0" /> 
                 <element name="E_SD" type="xs:string" minOccurs="0" /> 
                 <element name="FOGN" type="xs:string" minOccurs="0" /> 
                 <element name="FRAN" type="xs:string" minOccurs="0" /> 
                 <element name="GREC" type="xs:string" minOccurs="0" /> 
                 <element name="MFTV" type="xs:string" minOccurs="0" /> 
                 <element name="PRGP" type="xs:string" minOccurs="0" /> 
                 <element name="ROSN" type="xs:string" minOccurs="0" /> 
                 <element name="SLOV" type="xs:string" minOccurs="0" /> 
                 <element name="SVIZ" type="xs:string" minOccurs="0" /> 
                 <element name="TBRV" type="xs:string" minOccurs="0" /> 
                 <element name="PBNF" type="xs:string" minOccurs="0" /> 
               </sequence>
             </complexType>
           </element>
         </choice>
       </complexType>
     </element>
   </schema>
 <Prezzi>
  <Data>20080519</Data> 
  <Mercato>MGP</Mercato> 
  <Ora>1</Ora> 
  <PUN>70,138844</PUN> 
  <NAT>62</NAT> 
  <CALB>60,77</CALB> 
  <CNOR>60,77</CNOR> 
  <CSUD>60,77</CSUD> 
  <NORD>60,77</NORD> 
  <SARD>75,12</SARD> 
  <SICI>198</SICI> 
  <SUD>60,77</SUD> 
  <AUST>0</AUST> 
  <BRNN>60,77</BRNN> 
  <COAC>75,12</COAC> 
  <CORS>75,12</CORS> 
  <E_CO>75,12</E_CO> 
  <E_NE>60,77</E_NE> 
  <E_NW>60,77</E_NW> 
  <E_SD>60,77</E_SD> 
  <FOGN>60,77</FOGN> 
  <FRAN>0</FRAN> 
  <GREC>0</GREC> 
  <MFTV>60,77</MFTV> 
  <PRGP>198</PRGP> 
  <ROSN>60,77</ROSN> 
  <SLOV>0</SLOV> 
  <SVIZ>0</SVIZ> 
  <TBRV>60,77</TBRV> 
  </Prezzi>
 <Prezzi>
  <Data>20080519</Data> 
  <Mercato>MGP</Mercato> 
  <Ora>2</Ora> 
  <PUN>45,049720</PUN> 
  <NAT>41,96</NAT> 
  <CALB>37,96</CALB> 
  <CNOR>37,96</CNOR> 
  <CSUD>37,96</CSUD> 
  <NORD>37,96</NORD> 
  <SARD>37,96</SARD> 
  <SICI>152</SICI> 
  <SUD>37,96</SUD> 
  <AUST>0</AUST> 
  <BRNN>37,96</BRNN> 
  <COAC>37,96</COAC> 
  <CORS>37,96</CORS> 
  <E_CO>37,96</E_CO> 
  <E_NE>37,96</E_NE> 
  <E_NW>37,96</E_NW> 
  <E_SD>37,96</E_SD> 
  <FOGN>37,96</FOGN> 
  <FRAN>0</FRAN> 
  <GREC>0</GREC> 
  <MFTV>37,96</MFTV> 
  <PRGP>152</PRGP> 
  <ROSN>37,96</ROSN> 
  <SLOV>0</SLOV> 
  <SVIZ>0</SVIZ> 
  <TBRV>37,96</TBRV> 
  </Prezzi>
</NewDataSet>

I actually get an error stating that <schema> is not expected or something similar.

Thank you very much in advance.

Federico

I've found a mate who helped me.
Thank you anyway.
Regards,
Federico

MBS Specialist since NAV 2.0
My experiences on Linkedin

Answers

  • kinekine Member Posts: 12,562
    The problem is that the Schema of the XML is part of the XML. Nav is not able to work with that and you will need to go around that in some way.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    Could you post for us how did you solved your problem? We are very curious people there... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • melsimmonsmelsimmons Member Posts: 1
    I had to work with an xml file that had a junk line that Navision would not accept, so I ran the file through Instream, changed the bad line and then moved the file to a temp file and then sent the temp file to the xmlport:

    InFile.CREATEINSTREAM(IStream);
    IStream.READTEXT(firstLine); ///first line is ok
    Tempfile.WRITE(firstLine);
    IStream.READTEXT(firstLine);
    Tempfile.WRITE('<OrderLog>'); ///this line has junk so change tag

    WHILE NOT (IStream.EOS()) DO
    BEGIN
    IStream.READTEXT(firstLine);
    Tempfile.WRITE(firstLine);
    END;

    Tempfile.CREATEINSTREAM(IStream);
    CLEAR(XML);
    XML.SETSOURCE(IStream);
    XML.IMPORT;
  • ebsoftebsoft Member Posts: 81
    kine wrote:
    Could you post for us how did you solved your problem? We are very curious people there... 8)

    Hope you were talking to me...

    I've used a function used elsewhere in NAV:
    RemoveNamespace(XMLSourceDocument : Automation "'Microsoft XML, v4.0'.DOMDocument40";VAR XMLDestinationDocument : Automation "'Microsof
    TempTable.Picture.CREATEOUTSTREAM(OutStreamStylesheet);
    TempTable.Picture.CREATEINSTREAM(InStreamStylesheet);
    
    WITH OutStreamStylesheet DO BEGIN
      WRITETEXT('<?xml version="1.0" encoding="UTF-8"?>');
      WRITETEXT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">');
      WRITETEXT('<xsl:output method="xml" encoding="UTF-8" />');
      WRITETEXT('<xsl:template match="/">');
      WRITETEXT('<xsl:copy>');
      WRITETEXT('<xsl:apply-templates />');
      WRITETEXT('</xsl:copy>');
      WRITETEXT('</xsl:template>');
      WRITETEXT('<xsl:template match="*">');
      WRITETEXT('<xsl:element name="{local-name()}">');
      WRITETEXT('<xsl:apply-templates select="@* | node()" />');
      WRITETEXT('</xsl:element>');
      WRITETEXT('</xsl:template>');
      WRITETEXT('<xsl:template match="@*">');
      WRITETEXT('<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>');
      WRITETEXT('</xsl:template>');
      WRITETEXT('<xsl:template match="text() | processing-instruction() | comment()">');
      WRITETEXT('<xsl:copy />');
      WRITETEXT('</xsl:template>');
      WRITETEXT('</xsl:stylesheet>');
    END;
    
    IF ISCLEAR(XMLStyleSheet) THEN
      IF NOT CREATE(XMLStyleSheet) THEN
        EXIT(FALSE);
    
    IF NOT XMLStyleSheet.load(InStreamStylesheet) THEN
      EXIT(FALSE);
    
    IF ISCLEAR(XMLDestinationDocument) THEN
      IF NOT CREATE(XMLDestinationDocument) THEN
        EXIT(FALSE);
    
    XMLSourceDocument.transformNodeToObject(XMLStyleSheet,XMLDestinationDocument);
    
    EXIT(TRUE);
    

    This removed xs schema that NAV does not like very much.
    So I could import correctly the XML file in my Table.
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
Sign In or Register to comment.