Форум программистов, компьютерный форум, киберфорум
Java
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.55/11: Рейтинг темы: голосов - 11, средняя оценка - 4.55
0 / 0 / 0
Регистрация: 13.11.2016
Сообщений: 4
1

JAXB пространство имен, генерация классов из xsd

02.12.2019, 10:44. Показов 2241. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
День добрый ! Хобийно занимаюсь кодингом (программированием) очень мне нравится то дело . Сам работаю технологом на заводе . Это вводная часть , что бы прям сильно не ругались на меня за вопросы ниже .
Есть задача формировать xml-файл и передавать его в 1с.

вот xsd из 1С
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<xs:schema xmlns:ns1="http://v8.1c.ru/8.1/data/enterprise/current-config" xmlns:tns="http://appius.ru/plm" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://appius.ru/plm" attributeFormDefault="unqualified" elementFormDefault="qualified">
    <xs:import namespace="http://v8.1c.ru/8.1/data/enterprise/current-config" schemaLocation="./currentconfig.xsd"/>
    <xs:element name="item" type="tns:item"/>
    <xs:complexType name="item">
        <xs:choice>
            <xs:element name="*******Group" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="element" type="tns:typeElement" nillable="true" minOccurs="0"/>
            <xs:element name="elementType" type="ns1:CatalogRef.plm_ВидыЭлементов" nillable="true" minOccurs="0"/>
            <xs:element name="link" type="tns:typeLink" nillable="true" minOccurs="0"/>
            <xs:element name="linkType" type="tns:typeLinkType" nillable="true" minOccurs="0"/>
            <xs:element name="items" type="tns:item" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="parameters" type="tns:parameter" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="presentation" type="tns:typePresentation" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="presentationParameters" type="tns:presentationParameter" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="UID" type="tns:typeUID" nillable="true" minOccurs="0"/>
            <xs:element name="GID" type="tns:typeUID" nillable="true" minOccurs="0"/>
            <xs:element name="MOD" type="ns1:CatalogRef.plm_ДескрипторыДоступа" nillable="true" minOccurs="0"/>
            <xs:element name="GMOD" type="ns1:CatalogRef.plm_ДескрипторыДоступа" nillable="true" minOccurs="0"/>
            <xs:element name="description" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="htmlContent" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="refContent" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="pictureBinaryData" type="xs:base64Binary" nillable="true" minOccurs="0"/>
            <xs:element name="pictureIndex" type="xs:integer" nillable="true" minOccurs="0"/>
            <xs:element name="sequenceNumber" type="xs:integer" nillable="true" minOccurs="0"/>
            <xs:element name="created" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="added" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="replaced" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="deleted" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="modified" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="revised" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="dataVersion" type="xs:integer" nillable="true" minOccurs="0"/>
            <xs:element name="reverseLink" type="xs:boolean" nillable="true" minOccurs="0"/>
        </xs:choice>
    </xs:complexType>
    
    <xs:complexType name="parameter">
        <xs:choice>
            <xs:element name="reference" type="tns:typeParameter"/>
            <xs:element name="description" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="property" type="ns1:ChartOfCharacteristicTypesRef.plm_Свойства" nillable="true" minOccurs="0"/>
            <xs:element name="value" nillable="true" minOccurs="0"/>
            <xs:element name="unit" type="ns1:CatalogRef.УпаковкиЕдиницыИзмерения" nillable="true" minOccurs="0"/>
            <xs:element name="linkParameter" type="xs:boolean" nillable="true" minOccurs="0"/>
            <xs:element name="parameters" type="tns:parameter" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="presentationParameter">
        <xs:choice>
            <xs:element name="parameter" type="tns:typePresentation" nillable="true" minOccurs="0"/>
            <xs:element name="prefix" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="postfix" type="xs:string" nillable="true" minOccurs="0"/>
        </xs:choice>
    </xs:complexType>
    <xs:simpleType name="typeElement">
        <xs:union memberTypes="ns1:CatalogRef.plm_ЭлементыСтруктуры"/>
    </xs:simpleType>
    <xs:simpleType name="typeLink">
        <xs:union memberTypes="ns1:CatalogRef.plm_ЭлементыСвязей ns1:CatalogRef.plm_ВертикальныеСвязи"/>
    </xs:simpleType>
    <xs:simpleType name="typeLinkType">
        <xs:union memberTypes="ns1:CatalogRef.plm_ШаблоныТехнологическихСвязей ns1:EnumRef.plm_ВидыВертикальныхСвязей"/>
    </xs:simpleType>
    <xs:simpleType name="typeParameter">
        <xs:union memberTypes="ns1:CatalogRef.plm_ПараметрыЭлементов ns1:CatalogRef.plm_ПараметрыСвязей"/>
    </xs:simpleType>
    <xs:simpleType name="typePresentation">
        <xs:union memberTypes="xs:string ns1:CatalogRef.plm_ПараметрыЭлементов ns1:CatalogRef.plm_ПараметрыСвязей"/>
    </xs:simpleType>
    <xs:simpleType name="typeUID">
        <xs:union memberTypes="ns1:CatalogRef.Пользователи ns1:CatalogRef.ГруппыПользователей ns1:EnumRef.plm_СистемныеГруппы"/>
    </xs:simpleType>
</xs:schema>
Что сделал читаю с помощью XPath все читать надо совсем чуть чуть . А вот потом пришла идея формировать абсолютно новый документ и решил попытать счастье с JAXB . Выгрузил схемы xsd из 1C их оказалось 4 первая ссылается на вторую у второй еще две директивы импорта . JAXB сгенерил мне 200+ классов из этих схем весьма странным образом. При чтении все прочитал а вот при записи мой XML 1C не принял. Потому как пространство имен не совпадало и типы не прописывались там где они должны быть. Посмотрел внимательно и запутался окончательно . Например у типа параметр есть элемент value В классе Parametr он выглядит так

Java
1
2
 @XmlElementRef(name = "value", namespace = "http://appius.ru/plm", type = JAXBElement.class, required = false)
    protected JAXBElement<Object> value;
а другие
например reference в этом же классе

сформирована как
Java
1
 protected String reference;

Пытался добавить в схему

XML
1
<xs:element name="item" type="tns:item"/>
Чтобы получить корневой элемент при формировании классов но что то не вышло ничего . Вобщем если кто не пожалеет своего времени и направит меня в нужную сторону ))) Буду безумно благодарен уж очень хочется разобраться с JAXB гуглил читал но не хватило моего понимания пока а нормального примера для осознания не нашел .
а ну и приложу выходной файл который валидный и его 1с принимает . ПОлучилось "много букаф" поэтому если надо приложу во втором сообщении.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
02.12.2019, 10:44
Ответы с готовыми решениями:

XSD генерация Entity классов и чтение xml
Я новичок в Java. Есть описание формата XSD и XML файл 2 Гига. Необходимо занести данные из XML...

Пространство имен и видимость классов с модификатором private
Добрый день ! С какой целью стоит private перед классом K ? По началу думал , что этот класс...

Какое пространство имен и статические методы классов
Доброго времени суток :) Судя из названия темы, понимаем что автор жжет. Подскажите где в...

Автозагрузка, пространство имен и вызов встроенных в php классов
Всем доброго времени суток. Есть следующий код для соединения с БД: namespace database; class...

1
0 / 0 / 0
Регистрация: 13.11.2016
Сообщений: 4
03.12.2019, 15:52  [ТС] 2
Вот такой получается выходной файл .

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<item xmlns="http://appius.ru/plm" xmlns:ns2="http://v8.1c.ru/8.1/data/enterprise/current-config" xmlns:ns3="http://v8.1c.ru/8.1/data/core" xmlns:ns4="http://v8.1c.ru/8.1/data/enterprise" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <*******Group>false</*******Group>
    <element>aa054c67-7c71-11e9-bba4-288023aa25ab</element>
    <elementType>79634c36-cd48-44eb-aadc-55815267fdaf</elementType>
    <link xsi:nil="true"/>
    <linkType xsi:nil="true"/>
    <items>
        <*******Group>false</*******Group>
        <element>66973de1-7c73-11e9-bba4-288023aa25ab</element>
        <elementType>1c572e0a-2ade-497e-b8bf-b585f3bc468e</elementType>
        <link xsi:nil="true"/>
        <linkType>65a18338-5a8d-4402-9b38-e4632139a094</linkType>
        <items>
            <*******Group>false</*******Group>
            <element>66973df6-7c73-11e9-bba4-288023aa25ab</element>
            <elementType>82dec47e-3721-466a-9c26-dd2641fd0b81</elementType>
            <link xsi:nil="true"/>
            <linkType>21aa8f9c-a59d-4325-a144-c9db70440b7d</linkType>
            <parameters>
                <reference>66973df7-7c73-11e9-bba4-288023aa25ab</reference>
                <description>ERP</description>
                <value xsi:nil="true"/>
                <linkParameter>false</linkParameter>
                <parameters>
                    <reference>66973df8-7c73-11e9-bba4-288023aa25ab</reference>
                    <description>Состояние</description>
                    <property>e71b60eb-33fe-4c53-894b-bc94ebe8317b</property>
                    <value xmlns:d6p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="d6p1:EnumRef.plm_СостоянияЭлемента">Разработка</value>
                    <unit>00000000-0000-0000-0000-000000000000</unit>..................

А я ожидаю вот такой
XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>
<item xmlns="http://appius.ru/plm" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="item">
    <*******Group>false</*******Group>
    <element xmlns:d2p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d2p1:CatalogRef.plm_ЭлементыСтруктуры">aa054c67-7c71-11e9-bba4-288023aa25ab</element>
    <elementType>79634c36-cd48-44eb-aadc-55815267fdaf</elementType>
    <link xsi:nil="true"/>
    <linkType xsi:nil="true"/>
    <items>
        <*******Group>false</*******Group>
        <element xmlns:d3p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d3p1:CatalogRef.plm_ЭлементыСтруктуры">66973de1-7c73-11e9-bba4-288023aa25ab</element>
        <elementType>1c572e0a-2ade-497e-b8bf-b585f3bc468e</elementType>
        <link xsi:nil="true"/>
        <linkType xmlns:d3p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d3p1:CatalogRef.plm_ШаблоныТехнологическихСвязей">65a18338-5a8d-4402-9b38-e4632139a094</linkType>
        <items>
            <*******Group>false</*******Group>
            <element xmlns:d4p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d4p1:CatalogRef.plm_ЭлементыСтруктуры">66973df6-7c73-11e9-bba4-288023aa25ab</element>
            <elementType>82dec47e-3721-466a-9c26-dd2641fd0b81</elementType>
            <link xsi:nil="true"/>
            <linkType xmlns:d4p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d4p1:CatalogRef.plm_ШаблоныТехнологическихСвязей">21aa8f9c-a59d-4325-a144-c9db70440b7d</linkType>
            <parameters>
                <reference xmlns:d5p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d5p1:CatalogRef.plm_ПараметрыЭлементов">66973df7-7c73-11e9-bba4-288023aa25ab</reference>
                <description>ERP</description>
                <value xsi:nil="true"/>
                <linkParameter>false</linkParameter>
                <parameters>
                    <reference xmlns:d6p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d6p1:CatalogRef.plm_ПараметрыЭлементов">66973df8-7c73-11e9-bba4-288023aa25ab</reference>
                    <description>Состояние</description>
                    <property>e71b60eb-33fe-4c53-894b-bc94ebe8317b</property>
                    <value xmlns:d6p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d6p1:EnumRef.plm_СостоянияЭлемента">Разработка</value>
                    <unit>00000000-0000-0000-0000-000000000000</unit>
                    <linkParameter>false</linkParameter> ......

При чем только вот этот элемент value
XML
1
<value xmlns:d6p1="http://v8.1c.ru/8.1/data/enterprise/current-config" xsi:type="d6p1:EnumRef.plm_СостоянияЭлемента"></value>
при автоматической генерации имеет вот вид JAXBElement<Object> что в нем такого особенного почему только он ? Кто нибудь может мне это объяснить. Спасибо заранее
0
03.12.2019, 15:52
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
03.12.2019, 15:52
Помогаю со студенческими работами здесь

Имя типа или пространство имён sess отсутствуют в классе или в пространстве имён user
Привет Написана страничка User в ней: namespace user { public class user :System.tralala {...

Имя типа или пространство имен "Object" отсутствует в пространстве имен "System.Data"
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;...

Пространство имен
Как собственно сделать что бы &quot;string ch = my.change + &quot;.txt&quot;;&quot; было что я написал, а не...

Пространство имен
&quot;Terrasodt.Core.DB.Query&quot; не содержит определение для &quot;ExecuteReader&quot;. Не удалось найти метод...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru