JAXB -Kontext erwartet einen leeren Namespace, egal was passiertJava

Java-Forum
Anonymous
 JAXB -Kontext erwartet einen leeren Namespace, egal was passiert

Post by Anonymous »

Ich habe ein Problem, wenn ich mit JAXB ein XML zu meinen XJC -Schema -basierten Klassen mit JAXB abmerklegt habe. Ich habe jeden Beitrag gelesen, den ich bisher gefunden habe, und versucht bereits, wer ohne Erfolg weiß, wie viele Dinge, ohne Erfolg. Unmarshall die Datei nodeset2.xml zur generierten Klasse uanodeset (Root-Element) wie:

Code: Select all

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();
Dies gibt Folgendes aus:

JAXB Ereignis: Unerwartetes Element
(uri:"http://opcfoundation.org/ua/20/03/uanodeset.xsd",ell/> Local: "Modelle:" Models "). Erwartete Elemente sind
, , , , ,
JAXB Ereignis: unerwartetes Element
JAXB Ereignis: unerwartetes Element
(uri:"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
Lokal: "Aliases"). Erwartete Elemente sind
, , , , ,
JAXB Ereignis: unerwartetes Element
JAXB Ereignis: unerwartetes Element
(uri:"http://opcfoundation.org/ua/2011/03/uanodeset.xsd", Adbr/> Lokal: "uaObject"). Erwartete Elemente sind
, , , , ,
JAXB Ereignis: unerwartetes Element
JAXB Ereignis: unerwartetes Element
(uri:"http://opcfoundation.org/ua/2011/03/uanodeset.xsd", Adbr/> Lokal: "uaObject"). Erwartete Elemente sind
, , , , ,
JAXB Ereignis: unerwartetes Element
JAXB Ereignis: unerwartetes Element
(uri:"http://opcfoundation.org/ua/2011/03/uanodeset.xsd",
Lokal: "uadatatyp"). Erwartete Elemente sind
, , , , , < /p>
. Uanodeset Objekt mit null Werte.

Code: Select all

nodeset.generated
) mit dem folgenden Inhalt:

Code: Select all

@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;
Um als Referenz zu haben.

Code: Select all

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;

...
Dinge, die ich ausprobiert habe

[*] Instankten Sie den JAXBContext aus uanodeset.class (code> (

Code: Select all

JAXBContext context = JAXBContext.newInstance(UANodeSet.class);
) => nothing has changed
[*]Add manually namespace = "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" to @XmlTypes and/or @XmlElements @XmlRootElement => JAXBContext continues to say the expected elements are ,,,,,
Removing package-info.java file completely, and add the Namespace = "http://opcfoundation.org/ua/2011/03/uanodeset.xsd" Attribut überall (überall (

Code: Select all

@XmlType
s, @xmlelement s, @xmlrootelement ) => Keine Änderungen. Long schon.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post