Java/JAXB : Adding id to my element without making this appear in the XML file











up vote
0
down vote

favorite












I want to add an id to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute nor @XmlElement, but it always appears. I just want to set my id for my object, to get it back for something else in my program.



Here is my Java code in JAXB (simplified) :



public class Equipment {
private String label;
private Integer id;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}

@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}


And here it is the result when I create my XML file :



<site label="test">
<equipment id="2" label="test">
</equipment>
</site>


As you can see id appears, but it shouldn't.

Thanx !










share|improve this question




























    up vote
    0
    down vote

    favorite












    I want to add an id to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute nor @XmlElement, but it always appears. I just want to set my id for my object, to get it back for something else in my program.



    Here is my Java code in JAXB (simplified) :



    public class Equipment {
    private String label;
    private Integer id;

    public Integer getId() {
    return id;
    }
    public void setId(Integer id) {
    this.id = id;
    }

    @XmlAttribute
    public String getLabel() {
    return label;
    }
    public void setLabel(String label) {
    this.label = label;
    }
    }


    And here it is the result when I create my XML file :



    <site label="test">
    <equipment id="2" label="test">
    </equipment>
    </site>


    As you can see id appears, but it shouldn't.

    Thanx !










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to add an id to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute nor @XmlElement, but it always appears. I just want to set my id for my object, to get it back for something else in my program.



      Here is my Java code in JAXB (simplified) :



      public class Equipment {
      private String label;
      private Integer id;

      public Integer getId() {
      return id;
      }
      public void setId(Integer id) {
      this.id = id;
      }

      @XmlAttribute
      public String getLabel() {
      return label;
      }
      public void setLabel(String label) {
      this.label = label;
      }
      }


      And here it is the result when I create my XML file :



      <site label="test">
      <equipment id="2" label="test">
      </equipment>
      </site>


      As you can see id appears, but it shouldn't.

      Thanx !










      share|improve this question















      I want to add an id to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute nor @XmlElement, but it always appears. I just want to set my id for my object, to get it back for something else in my program.



      Here is my Java code in JAXB (simplified) :



      public class Equipment {
      private String label;
      private Integer id;

      public Integer getId() {
      return id;
      }
      public void setId(Integer id) {
      this.id = id;
      }

      @XmlAttribute
      public String getLabel() {
      return label;
      }
      public void setLabel(String label) {
      this.label = label;
      }
      }


      And here it is the result when I create my XML file :



      <site label="test">
      <equipment id="2" label="test">
      </equipment>
      </site>


      As you can see id appears, but it shouldn't.

      Thanx !







      java xml jaxb attributes






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 14 hours ago









      Thomas Fritsch

      4,530121832




      4,530121832










      asked 17 hours ago









      Laliana

      32




      32
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          In your Equipment class you need to tell JAXB that it should ignore the
          id property. You do this by annotating it with @XmlTransient (instead of with
          @XmlAttribute or @XmlElement).



          @XmlTransient
          public Integer getId() {
          return id;
          }


          This should result in XML output like this:



          <site label="test">
          <equipment label="test"/>
          </site>





          share|improve this answer























          • Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
            – Laliana
            13 hours ago












          • @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
            – Thomas Fritsch
            13 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371852%2fjava-jaxb-adding-id-to-my-element-without-making-this-appear-in-the-xml-file%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          In your Equipment class you need to tell JAXB that it should ignore the
          id property. You do this by annotating it with @XmlTransient (instead of with
          @XmlAttribute or @XmlElement).



          @XmlTransient
          public Integer getId() {
          return id;
          }


          This should result in XML output like this:



          <site label="test">
          <equipment label="test"/>
          </site>





          share|improve this answer























          • Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
            – Laliana
            13 hours ago












          • @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
            – Thomas Fritsch
            13 hours ago















          up vote
          0
          down vote



          accepted










          In your Equipment class you need to tell JAXB that it should ignore the
          id property. You do this by annotating it with @XmlTransient (instead of with
          @XmlAttribute or @XmlElement).



          @XmlTransient
          public Integer getId() {
          return id;
          }


          This should result in XML output like this:



          <site label="test">
          <equipment label="test"/>
          </site>





          share|improve this answer























          • Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
            – Laliana
            13 hours ago












          • @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
            – Thomas Fritsch
            13 hours ago













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          In your Equipment class you need to tell JAXB that it should ignore the
          id property. You do this by annotating it with @XmlTransient (instead of with
          @XmlAttribute or @XmlElement).



          @XmlTransient
          public Integer getId() {
          return id;
          }


          This should result in XML output like this:



          <site label="test">
          <equipment label="test"/>
          </site>





          share|improve this answer














          In your Equipment class you need to tell JAXB that it should ignore the
          id property. You do this by annotating it with @XmlTransient (instead of with
          @XmlAttribute or @XmlElement).



          @XmlTransient
          public Integer getId() {
          return id;
          }


          This should result in XML output like this:



          <site label="test">
          <equipment label="test"/>
          </site>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 14 hours ago

























          answered 14 hours ago









          Thomas Fritsch

          4,530121832




          4,530121832












          • Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
            – Laliana
            13 hours ago












          • @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
            – Thomas Fritsch
            13 hours ago


















          • Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
            – Laliana
            13 hours ago












          • @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
            – Thomas Fritsch
            13 hours ago
















          Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
          – Laliana
          13 hours ago






          Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
          – Laliana
          13 hours ago














          @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
          – Thomas Fritsch
          13 hours ago




          @Laliana Glad to hear this :) You should accept the answer if it solved your problem.
          – Thomas Fritsch
          13 hours ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371852%2fjava-jaxb-adding-id-to-my-element-without-making-this-appear-in-the-xml-file%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          ts Property 'filter' does not exist on type '{}'

          mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window