About Read XML Files?



1C:Enterprise platform integration capabilities and techniques

#1
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Feb 26, 2015
Company: Uguz Limited sirketi

Hello there.
I have one XML file.
How can I read this file?

Code
<?xml version="1.0" encoding="utf-8"?>
<MAINGROUP>
  <CATEGORY CODE="DES1" DESCRIPTION="CATEGORY DESCRIPTION">
    <GRUP CODE="8" DESCRIPTION="GROUP DESCRIPTION">
      <PRODUCT CODE="TRU20653" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
      <PRODUCT CODE="TRU20657" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
    </GRUP>
  </CATEGORY>
  <CATEGORY CODE="DES3" DESCRIPTION="CATEGORY DESCRIPTION">
    <GRUP CODE="25" DESCRIPTION="GROUP DESCRIPTION">
      <PRODUCT CODE="INBNMPBDPX831" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
        <ATTRBTS>
          <ATRBB DESCRIPTION="ATB01" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB02" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB03" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB04" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB05" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB06" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB07" ATTRVALUE="HAVEFUN" />
          <ATRBB DESCRIPTION="ATB08" ATTRVALUE="3" />
        </ATTRBTS>
      </PRODUCT>
    </GRUP>
    <GRUP CODE="29" DESCRIPTION="GROUP DESCRIPTION">
      <PRODUCT CODE="PDFM11LBX1APLEU" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
      <PRODUCT CODE="PDFM11LABX1APLEU" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
      <PRODUCT CODE="PDFM12L-ABX1-MEA" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
      <PRODUCT CODE="PDFM12L-BX1-MEA" PRODUCTNAME="PRODUCT NAME" MARKA="MARKA" GLOBALCODE="GLOBALCODE" SIRKETCODE="UGUZ">
        <TAX>TAX18</TAX>
        <IMAGE>http://sampleurl.com/image.jpg</IMAGE>
      </PRODUCT>
    </GRUP>
  </CATEGORY>
...
...
...


I did a study.
I was not exactly successful.
Sample:

Code
XMLReader = New XMLReader;
   
   Try
        XMLReader.OpenFile("string path file");
 
    Except

   EndTry;
   
   While XMLReader.Read() Do
      Try
         Message(XMLReader.AttributeName(0)+"-"+ XMLReader.AttributeValue(0));
      
      Except
      
      EndTry; 
   EndDo; 



There are tables inside.
How can I read this?
I want to read and print the console as a message.
(Message (.....))

Edited: Erdogan Uguz - Nov 06, 2016 02:15 PM
 
#2
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Erdogan.
Please, see an example in the How to read and write XML using XDTO topic.

 
#3
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Nov 8, 2016
Company:

hi, not necessarily use XDTO, XML can be read in a loop
ex.

Code
XMLReader = New XMLReader;
XMLReader.OpenFile(nameFile);
While XMLReader.Read() Do
   //work
EndDo;

 
#4
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Apr 18, 2012
Company:

Hi everyone.

Here is example with DOMDocument. I think this is the best solution in this case.

Code
For Each ElementCategory In DOMDocument.DocumentElement.ChildNodes Do
   Message(ElementCategory.GetAttribute("DESCRIPTION"));
   Message(ElementCategory.GetAttribute("CODE"));
   
   ElementsGRUP = ElementCategory.GetElementByTagName("GRUP");
   
   For Each ElementGRUP In ElementsGRUP Do
      Message(ElementGRUP.GetAttribute("DESCRIPTION"));
      Message(ElementGRUP.GetAttribute("CODE"));
      For Each ElementProduct In  ElementGRUP.GetElementByTagName("PRODUCT") Do
         Message(ElementProduct.GetAttribute("PRODUCTNAME"));
         Message(ElementProduct.GetElementByTagName("TAX")[0].TextContent);
      EndDo;
   EndDo;
EndDo;

Edited: Alexei Khatin - Nov 08, 2016 09:48 AM
 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)