Форум 1С
Программистам, бухгалтерам, администраторам, пользователям
Задай вопрос - получи решение проблемы
25 ноя 2024, 19:51

чтение xml по xsd-схеме

Автор Cyrix, 22 дек 2018, 21:32

0 Пользователей и 1 гость просматривают эту тему.

Cyrix

Здравствуйте!

есть схема sxd (cheki.xsd) :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:tns="http://www.crystals.ru" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.crystals.ru">
<xs:element name="purchases">
<xs:complexType>
<xs:sequence>
<xs:element name="purchase" type="purchaseType" form="qualified" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
<xs:attribute name="count" type="xs:long">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:simpleType name="card-typeType">
<xs:restriction base="xs:string">
<xs:enumeration value="INTERNAL"/>
<xs:enumeration value="EXTERNAL"/>
<xs:enumeration value="PRESENT"/>
<xs:enumeration value="BONUS"/>
<xs:enumeration value="COUPON_CARD"/>
<xs:enumeration value="COUPON_RECEIPT"/>
<xs:enumeration value="COUPON_PROCESSING"/>
<xs:enumeration value="COUPON_UNIQUE"/>
<xs:enumeration value="UNKNOWN"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="positionsType">
<xs:sequence>
<xs:element name="position" type="positionType" form="qualified" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="paymentsType">
<xs:sequence>
<xs:element name="payment" type="paymentType" form="qualified" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="discountType">
<xs:attribute name="positionId" type="xs:long" use="required"/>
<xs:attribute name="goodCode" type="xs:string"/>
<xs:attribute name="amount" type="xs:double" use="required"/>
<xs:attribute name="isDiscountPurchase" type="xs:boolean" use="required"/>
<xs:attribute name="AdvertActGUID" type="xs:long" use="required"/>
<xs:attribute name="AdvertActExternalCode" type="xs:string"/>
<xs:attribute name="advertType" type="xs:string" use="required"/>
<xs:attribute name="AdvertActDiscountType" type="xs:string" use="required"/>
<xs:attribute name="card-number" type="xs:string"/>
<xs:attribute name="quantity" type="xs:double"/>
<xs:attribute name="externalActionId" type="xs:string"/>
</xs:complexType>
<xs:complexType name="bonusDiscountType">
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="transaction-id" type="xs:base64Binary" use="required"/>
</xs:complexType>
<xs:complexType name="bonusesType">
<xs:sequence>
<xs:element name="bonus" type="bonusesTransactionType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bonusesTransactionType">
<xs:attribute name="transactionId" type="xs:string"/>
<xs:attribute name="bonusesType" type="xs:string" use="required"/>
<xs:attribute name="chargeOnBonuses" type="xs:double"/>
<xs:attribute name="writeOffBonuses" type="xs:double"/>
<xs:attribute name="cardNumber" type="xs:string" use="required"/>
<xs:attribute name="cardGuid" type="xs:string"/>
<xs:attribute name="bonusaccountsid" type="xs:long"/>
<xs:attribute name="AdvertActExternalCode" type="xs:string"/>
<xs:attribute name="AdvertActDiscountType" type="xs:string"/>
<xs:attribute name="AdvertActGUID" type="xs:long"/>
</xs:complexType>
<xs:complexType name="purchaseType">
<xs:sequence>
<xs:sequence>
<xs:element name="plugin-property" type="plugin-propertyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:element name="positions" type="positionsType" form="qualified" minOccurs="0"/>
<xs:element name="payments" type="paymentsType" form="qualified" minOccurs="0"/>
<xs:element name="discounts" type="discountsType" form="qualified" minOccurs="0"/>
<xs:element name="discountCards" type="discountCardsType" form="qualified" minOccurs="0"/>
<xs:element name="card" type="cardType" form="qualified" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="original-purchase" type="purchaseType" form="qualified" minOccurs="0"/>
<xs:element name="bonus-discount" type="bonusDiscountType" form="qualified" minOccurs="0"/>
<xs:element name="bonuses" type="bonusesType" maxOccurs="1" minOccurs="0"/>
<xs:element name="exciseBottles" type="exciseBottlesType" form="qualified" minOccurs="0"/>
<xs:element name="presents" type="presentsType" form="qualified" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="tabNumber" type="xs:string"/>
<xs:attribute name="userName" type="xs:string"/>
<xs:attribute name="operationType" type="xs:boolean" default="true"/>
<xs:attribute name="operDay" type="xs:date" use="required"/>
<xs:attribute name="shop" type="xs:long" use="required"/>
<xs:attribute name="cash" type="xs:long" use="required"/>
<xs:attribute name="shift" type="xs:long" use="required"/>
<xs:attribute name="number" type="xs:long" use="required"/>
<xs:attribute name="saletime" type="xs:dateTime"/>
<xs:attribute name="begintime" type="xs:dateTime"/>
<xs:attribute name="amount" type="xs:double"/>
<xs:attribute name="discountAmount" type="xs:double"/>
<xs:attribute name="denyPrintToDocuments" type="xs:boolean"/>
<xs:attribute name="clientType" type="client_Type"/>
<xs:attribute name="client_guid" type="xs:long"/>
</xs:complexType>
<xs:complexType name="discountCardsType">
<xs:sequence>
<xs:element name="discountCard" type="xs:string" form="qualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="discountsType">
<xs:sequence>
<xs:element name="discount" type="discountType" form="qualified" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="positionType">
<xs:sequence>
<xs:element name="plugin-property" type="plugin-propertyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="order" type="xs:long" use="required"/>
<xs:attribute name="departNumber" type="xs:long" use="required"/>
<xs:attribute name="goodsCode" type="xs:string" use="required"/>
<xs:attribute name="barCode" type="xs:string" use="required"/>
<xs:attribute name="count" type="xs:double" use="required"/>
<xs:attribute name="cost" type="xs:double" use="required"/>
<xs:attribute name="nds" type="xs:double" use="required"/>
<xs:attribute name="ndsClass" type="xs:string" use="required"/>
<xs:attribute name="ndsSum" type="xs:double" use="required"/>
<xs:attribute name="discountValue" type="xs:double" use="required"/>
<xs:attribute name="costWithDiscount" type="xs:double" use="required"/>
<xs:attribute name="amount" type="xs:double" use="required"/>
<xs:attribute name="softCheckNumber" type="xs:string" use="optional"/>
<xs:attribute name="insertType" type="xs:int" use="optional"/>
</xs:complexType>
<xs:complexType name="cardType">
<xs:attribute name="type" type="card-typeType"/>
<xs:attribute name="card_type_guid" type="xs:long"/>
<xs:attribute name="number" type="xs:string" use="required"/>
<xs:attribute name="guid" type="xs:string"/>
</xs:complexType>
<xs:complexType name="plugin-propertyType">
<xs:sequence>
<xs:element name="plugin-property" type="plugin-propertyType" form="qualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="key" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
<xs:complexType name="paymentType">
<xs:sequence>
<xs:element name="plugin-property" type="plugin-propertyType" form="qualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="typeClass" type="xs:string" use="required"/>
<xs:attribute name="amount" type="xs:double" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
</xs:complexType>
<xs:simpleType name="client_Type">
<xs:restriction base="xs:string">
<xs:enumeration value="PRIVATE"/>
<xs:enumeration value="JURISTIC_PERSON"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="exciseBottlesType">
<xs:sequence>
<xs:element name="bottle" type="exciseBottleType" form="qualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="exciseBottleType">
<xs:attribute name="barcode" type="xs:string"/>
<xs:attribute name="exciseBarcode" type="xs:string"/>
<xs:attribute name="setBarcode" type="xs:string"/>
<xs:attribute name="volume" type="xs:double"/>
<xs:attribute name="price" type="xs:double"/>
</xs:complexType>
<xs:complexType name="presentsType">
<xs:sequence>
<xs:element name="present" type="presentType" form="qualified" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="actionname" type="xs:string"/>
<xs:attribute name="externalcode" type="xs:string"/>
<xs:attribute name="guid" type="xs:string"/>
<xs:attribute name="issued" type="xs:int"/>
<xs:attribute name="scanned" type="xs:int"/>
</xs:complexType>
<xs:complexType name="presentType">
<xs:attribute name="amount" type="xs:int"/>
<xs:attribute name="condition" type="xs:string"/>
</xs:complexType>
</xs:schema>


есть файл xml (purchases.xml) который нужно прочитать:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchases xmlns="http://www.crystals.ru" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" count="2">
<purchase tabNumber="6" userName="Кассирова К. К." operationType="true" operDay="2018-12-17+03:00" shop="2" cash="1" shift="224" number="3" saletime="2018-12-17T10:03:19.280+03:00" begintime="2018-12-17T10:02:47.783+03:00" amount="220.0" discountAmount="0.0" inn="">
<positions>
<position order="2" departNumber="2" goodsCode="1026" barCode="2100000005901" count="3.0" cost="40.0" nds="-1.0" ndsSum="0.0" discountValue="0.0" costWithDiscount="40.0" amount="120.0" dateCommit="2018-12-17T10:02:54.549+03:00"/>
<position order="1" departNumber="2" goodsCode="1007" barCode="2100000001453" count="4.0" cost="25.0" nds="-1.0" ndsSum="0.0" discountValue="0.0" costWithDiscount="25.0" amount="100.0" dateCommit="2018-12-17T10:02:47.884+03:00"/>
</positions>
<payments>
<payment typeClass="BankCardPaymentEntity" amount="220.0" description="Оплата по банковской карте">
<plugin-property key="card.hash" value="5FA8037E8044EDB9905C914E505F261FCC275AFC"/>
<plugin-property key="terminal.number" value="10577175"/>
<plugin-property key="cash.transaction.id" value="325015"/>
<plugin-property key="cash.transaction.date" value="2018-12-17 10:03:15.380"/>
<plugin-property key="bank.id" value="Сбербанк"/>
<plugin-property key="auth.code" value="290964"/>
<plugin-property key="card.type" value="MIR Credit"/>
<plugin-property key="bank.type" value="SBERBANK"/>
<plugin-property key="card.number" value="220220******5909"/>
</payment>
</payments>
</purchase>
<purchase tabNumber="6" userName="Кассирова К. К." operationType="true" operDay="2018-12-17+03:00" shop="2" cash="1" shift="224" number="4" saletime="2018-12-17T10:04:19.136+03:00" begintime="2018-12-17T10:04:07.458+03:00" amount="70.0" discountAmount="0.0" inn="">
<positions>
<position order="2" departNumber="2" goodsCode="1006" barCode="2100000004089" count="1.0" cost="37.0" nds="-1.0" ndsSum="0.0" discountValue="0.0" costWithDiscount="37.0" amount="37.0" dateCommit="2018-12-17T10:04:08.781+03:00"/>
<position order="1" departNumber="1" goodsCode="1025" barCode="2100000005840" count="1.0" cost="33.0" nds="-1.0" ndsSum="0.0" discountValue="0.0" costWithDiscount="33.0" amount="33.0" dateCommit="2018-12-17T10:04:07.577+03:00"/>
</positions>
<payments>
<payment typeClass="CashPaymentEntity" amount="70.0" description="Оплата наличными"/>
</payments>
</purchase>
</purchases>


читаю:

ТипФайлов = "purchases";
ЧтениеXML = Новый ЧтениеXML;
ЧтениеXML.ОткрытьФайл("C:\purchases.xml");

ФайлыXSD = Новый Массив();
ФайлыXSD.Добавить("c:\cheki.xsd");
ЗагрузкаФабрикаXDTO = СоздатьФабрикуXDTO(ФайлыXSD);


ТипЧеки = ЗагрузкаФабрикаXDTO.Тип("http://www.crystals.ru", ТипФайлов);
Чеки = ЗагрузкаФабрикаXDTO.ПрочитатьXML(ЧтениеXML, ТипЧеки);

СписокЧеков = Чеки.purchase;
Индекс = 0;
Чек = СписокЧеков.Получить(Индекс);

ЧтениеXML.Закрыть();

СвойствоПозицияЧека = Чек.positions.Свойства().Получить("position");
ПозицииЧека = Чек.positions.ПолучитьСписок(СвойствоПозицияЧека);

СвойствоОплатаЧека = Чек.payments.Свойства().Получить("payment");
ОплатыЧека = Чек.payments.ПолучитьСписок(СвойствоОплатаЧека);


и в крайней строке получаю ошибку:
{ВнешняяОбработка.ЧтениеXML.Форма.Форма.Форма(32)}: Ошибка при вызове метода контекста (ПолучитьСписок)
ОплатыЧека = Чек.payments.ПолучитьСписок(СвойствоОплатаЧека);
по причине:
Несоответствие свойства и элемента данных XDTO:
Свойство: 'payment'
Свойство не является списковым


значит position у него является списковым, а payment вдруг перестал быть списковым!!! это как так??? :dfbsdfbsdf: помогите пожалуйста разобраться, уже всю голову сломал :xfbnsdfb:

antoneus

Насколько я знаю, 1С при чтении xml список с одним элементом воспринимает как ОбъектXDTO. Добавьте проверку - является ли payment объектом или списком.

Теги: XML xsd 

Похожие темы (5)

Рейтинг@Mail.ru

Поиск