|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2000
Città: Udine
Messaggi: 3178
|
[JAVA] Annotazione @XmlRootElement e namespace
Salve a tutti.
Sto cercando di serializzare un oggetto in xml utilizzando il package javax.xml.bind.annotation. La mia classe attualmente presenta questi campi (mostro solo l'inizio): Codice:
import java.util.*;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "items", namespace = "http://www.bibtex.org")
public class Bibliography
{
@XmlElement(name = "article")
public List<Article> articles;
@XmlElement(name = "book")
public List<Book> books;
@XmlElement(name = "booklet")
public List<Booklet> booklets;
@XmlElement(name = "conference")
public List<Conference> conferences;
Codice:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:items xmlns:ns2="http://www.bibtex.org">
<article id="MacKay92a">
<authors>
<authorslist>MacKay, D. J. C.</authorslist>
</authors>
<title>{B}ayesian Interpolation</title>
<journal>Neural Computation</journal>
<year>1992</year>
<volume>4</volume>
<number>3</number>
<pages>415--447</pages>
</article>
<article id="MacKay92b">
<authors>
<authorslist>MacKay, D. J. C.</authorslist>
</authors>
<title>A Practical {B}ayesian Framework for Backpropagation Networks</title>
<journal>Neural Computation</journal>
<year>1992</year>
<volume>4</volume>
<number>3</number>
<pages>448--472</pages>
<key>MacKay</key>
</article>
- personalizzare tale prefisso - o ancora meglio eliminarlo, cioò rendere quel namespace predefinito per piacere help!!! |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Oct 2000
Città: Udine
Messaggi: 3178
|
Quote:
Ho trovato il modo di cambiare prefisso (https://jaxb.dev.java.net/guide/Changing_prefixes.html) ma io vorrei proprio eliminarlo! Sapevo che non dovevo fidarmi di java |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Riesci ad allegare l'esempio?
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Cosi a me non lo da il namespace
Codice:
package it.xml;
import java.util.Date;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "items", namespace = "")
public class Person {
private String name;
private int age;
private Date dateOfBirth;
private String type;
public Person() {
}
public Person(String name, int age, Date dateOfBirth, String type) {
this.name = name;
this.age = age;
this.dateOfBirth = dateOfBirth;
this.setType(type);
}
@XmlElement()
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement()
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@XmlElement()
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
@XmlAttribute()
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public static void main(String args[]) throws Exception{
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Person person = new Person("Anonymous", 32, new Date(1970, 1, 10), "employee");
marshaller.marshal(person, System.out);
}
}
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Dec 2001
Città: Milano
Messaggi: 545
|
Magari il sentimento è reciproco
__________________
Angus the Hunter @ Realm of magic | Angus Young @ Batracer °SetiEmperor°| Ninja Technologies { qualunque cosa sia, è veloce e fa male (cit.) } |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Oct 2000
Città: Udine
Messaggi: 3178
|
@isAlreadyInUse
Io non voglio LEVARE il namespace, voglio che non abbia un prefisso (cioè sia quello di default) @ altri Bhè se il java non permette di fare questa SEMPLICISSIMA operazione, il problema non è il mio... poi vogliamo dire, se volessi aggiungere un altro namespace? |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
__________________
http://www.tevigroup.it/ |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 05:45.




















