मेरे पास निम्नलिखित संरचनाओं के साथ जावा क्लास हैं (कक्षा के नाम कुछ भी नहीं दर्शाते हैं, मैं उन्हें बस बना रहा था)।जेएक्सबी एक्सएमएल आउटपुट प्रारूप प्रश्न
package test;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@XmlRootElement
public class Test
{
@XmlAccessorType(XmlAccessType.FIELD)
static class Machine
{
@XmlElementWrapper(name="servers")
@XmlElement(name="server")
List<Server> servers = new ArrayList<Server>();
}
@XmlAccessorType(XmlAccessType.FIELD)
static class Server
{
Threshold t = new Threshold();
}
@XmlAccessorType(XmlAccessType.FIELD)
static class Threshold
{
RateThreshold load = new RateThreshold();
}
@XmlAccessorType(XmlAccessType.FIELD)
static class RateThreshold
{
@XmlAccessorType(XmlAccessType.FIELD)
static class Rate
{
int count;
Period period = new Period();
}
@XmlAccessorType(XmlAccessType.FIELD)
private static class Period
{
@XmlAttribute
private String type = "second";
@XmlValue
private float period;
}
Rate min = new Rate();
Rate max = new Rate();
}
@XmlElementWrapper(name="machines")
@XmlElement(name="machine")
List<Machine> machines = new ArrayList<Machine>();
public static void main(String[] args)
{
Machine m = new Machine();
Server s = new Server();
s.t.load.max.count = 10;
s.t.load.min.count = 1;
m.servers.add(s);
Test t = new Test();
t.machines.add(m);
JAXBContext jaxbContext;
Marshaller marshaller;
try
{
jaxbContext = JAXBContext.newInstance(Test.class);
marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(t, System.out);
}
catch (JAXBException e)
{
e.printStackTrace();
}
}
}
समस्या मैं कर रहा हूँ जब एक टेस्ट उदाहरण वास्ते JAXB द्वारा उत्पन्न XML आउटपुट के साथ है। XML आउटपुट हमेशा निम्न दिखाई देगा:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test>
<machines>
<machine>
<servers>
<server>
<t>
<load>
<min>
<count>1</count>
<period type="second">0.0</period>
</min>
<max>
<count>10</count>
<period type="second">0.0</period>
</max>
</load>
</t>
</server>
</servers>
</machine>
</machines>
</test>
आप देख सकते हैं, कुछ तत्वों को ठीक से इंडेंट नहीं किया जा रहा है (जो है, गहरे तत्वों, गिनती और अवधि)। ऐसा क्यों है? क्या मैंने जेएक्सबी संदर्भ बनाने के तरीके में कुछ गड़बड़ की है? या क्या अधिकतम सीमा है कि जेएक्सबी द्वारा कितने तत्वों को इंडेंट किया जा सकता है? मैं इसे कैसे ठीक कर सकता हूं? ध्यान दें कि मैंने JAXB_FORMATTED_OUTPUT को भी सही पर सेट किया है, लेकिन फिर भी अनुचित इंडेंटेशन प्राप्त करें।
धन्यवाद।
क्या आप इसे हल करने में सक्षम थे? मुझे जेएक्सबी का उपयोग करके जेनरेट किए गए मेरे एक्सएमएल में भी यही समस्या है। क्या आप सलाह दे सकते हैं ? –
@ शिवम शेखर, नहीं, समस्या अभी भी वहां है :(लेकिन यह अन्य चीजों की तुलना में कम महत्वपूर्ण है, इसलिए हमने इसे वहां छोड़ दिया – His