Hello, Mehmet Tuğrul SARIÇİÇEK.
Here is an example on how to read and write XML using XDTO:
Code |
---|
&AtServer
Procedure WriteAtServer()
TempFileName = GetTempFileName("xml");
// Defining object types.
ProductType = XDTOFactory.Type("http://www.sample-package.org", "Product");
ProductPriceType = XDTOFactory.Type("http://www.sample-package.org", "ProductPrice");
ProductPricesType = XDTOFactory.Type("http://www.sample-package.org", "ProductPrices");
ProductPricesXDTO = XDTOFactory.Create(ProductPricesType);
// Filling XDTO objects with data.
For Each Row In ProductPrices Do
ProductPriceXDTO = XDTOFactory.Create(ProductPriceType);
ProductXDTO = XDTOFactory.Create(ProductType);
Product = Row.Product.GetObject();
ProductXDTO.Code = Product.Code;
ProductXDTO.Description = Product.Description;
ProductPriceXDTO.Product = ProductXDTO;
ProductPriceXDTO.Price = Row.Price;
ProductPricesXDTO.List.Add(ProductPriceXDTO);
EndDo;
// Creating XML.
XMLWriter = New XMLWriter;
XMLWriter.OpenFile(TempFileName);
// Displaying XML.
TextDocument = New TextDocument;
TextDocument.Read(TempFileName);
XML = TextDocument.GetText();
DeleteFiles(TempFileName);
EndProcedure
&AtServer
Procedure ReadAtServer()
TempFileName = GetTempFileName("xml");
// Saving XML.
TextDocument = New TextDocument;
TextDocument.SetText(XML);
TextDocument.Write(TempFileName);
// Reading XML.
XMLReader = New XMLReader;
XMLReader.OpenFile(TempFileName);
// Filling the list.
ProductPrices.Clear();
ProductPricesType = XDTOFactory.Type("http://www.sample-package.org", "ProductPrices");
ProductPricesXDTO = XDTOFactory.ReadXML(XMLReader, ProductPricesType);
For Each ProductPriceXDTO In ProductPricesXDTO.List Do
ProductRef = Catalogs.Products.FindByCode(ProductPriceXDTO.Product.Code);
If Not ValueIsFilled(ProductRef) Then
ProductObject = Catalogs.Products.CreateItem();
ProductObject.Code = ProductPriceXDTO.Product.Code;
ProductObject.Description = ProductPriceXDTO.Product.Description;
ProductObject.Write();
ProductRef = ProductObject.Ref;
EndIf;
ProductPrice = ProductPrices.Add();
ProductPrice.Product = ProductRef;
ProductPrice.Price = ProductPriceXDTO.Price;
EndDo;
XMLReader.Close();
DeleteFiles(TempFileName);
EndProcedure |
The sample application is attached to this message.