Код: Выделить всё
String packageName = UANodeSet.class.getPackage().getName();
JAXBContext context = JAXBContext.newInstance(packageName);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setEventHandler(event -> {
System.err.println("JAXB EVENT: " + event.getMessage());
return true; // continue after error
});
String filePath = "C:/Users/mr/Downloads/Opc.Ua.NodeSet2.xml";
File file = new File(filePath);
JAXBElement nodeSet = (JAXBElement)unmarshaller.unmarshal(new StreamSource(file), UANodeSet.class);
UANodeSet nd = nodeSet.getValue();
jaxb Событие: неожиданный элемент
(URI:"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
Местные: "Модели"). Ожидаемые элементы -
, , , , ,
jaxb Событие: неожиданный элемент
(ури :"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
local: «псевдонимы»). Ожидаемые элементы -
, , , , ,
jaxb Событие: неожиданный элемент
(ури :"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
local: "uaobject"). Ожидаемые элементы -
, , , , ,
jaxb Событие: неожиданный элемент
(ури :"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
local: "uaobject"). Ожидаемые элементы -
, , , , ,
jaxb Событие: неожиданный элемент
(ури :"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
local: "uadatatype"). Ожидаемые элементы -
, , , , , < /p>
... карт /> < /blockvote>
и n -код. Uanodeset объект с null values.
Я подтверждаю, что у меня есть файл с именем package info.java в том же пакете (
Код: Выделить всё
nodeset.generatedКод: Выделить всё
@XmlSchema(
namespace = "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd",
elementFormDefault = XmlNsForm.QUALIFIED)
package nodeset.generated;
import jakarta.xml.bind.annotation.XmlNsForm;
import jakarta.xml.bind.annotation.XmlSchema;
Код: Выделить всё
package nodeset.generated;
import java.util.ArrayList;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElements;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlSchemaType;
import jakarta.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"namespaceUris",
"serverUris",
"models",
"aliases",
"extensions",
"uaObjectOrUAVariableOrUAMethod"
})
@XmlRootElement(name = "UANodeSet")
public class UANodeSet {
@XmlElement(name="NamespaceUris")
protected UriTable namespaceUris;
@XmlElement(name="ServerUris")
protected UriTable serverUris;
@XmlElement(name="Models")
protected ModelTable models;
@XmlElement(name="Aliases")
protected AliasTable aliases;
@XmlElement(name="Extensions")
protected ListOfExtensions extensions;
@XmlElements({
@XmlElement(name="UAObject", type = UAObject.class),
@XmlElement(name="UAVariable", type = UAVariable.class),
@XmlElement(name="UAMethod", type = UAMethod.class),
@XmlElement(name="UAView", type = UAView.class),
@XmlElement(name="UAObjectType", type = UAObjectType.class),
@XmlElement(name="UAVariableType", type = UAVariableType.class),
@XmlElement(name="UADataType", type = UADataType.class),
@XmlElement(name="UAReferenceType", type = UAReferenceType.class)
})
protected List uaObjectOrUAVariableOrUAMethod;
@XmlAttribute(name = "LastModified")
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar lastModified;
...
- создание jaxbcontext from uanodeset.class () => Ничто не изменилось
Код: Выделить всё
JAXBContext context = JAXBContext.newInstance(UANodeSet.class); - Добавить вручную имен -пространство = "http://opcfoundation.org/ua/2011/03/uanodeset.xsd" to @xmltype s и/или @xmlelement s @xmltelement /или @xmlelement @xml продолжает говорить, что ожидаемыми элементами являются , , , , ,
- removing-info.java namespace = "http://opcfoundation.org/ua/2011/03/uanodeset.xsd" Атрибут везде (s, @xmlelement s, @xmlrootelement ) => без изменений.
Код: Выделить всё
@XmlType
Подробнее здесь: https://stackoverflow.com/questions/795 ... atter-what