working on it ...

Filters

Explore Public Snippets

Sort by

Found 13k snippets matching: xml

    public by lbottaro modified Mar 31, 2014  355622  0  7  3

    Vendor class - Java example for marshalling/unmarshalling, using JAX-B XmlID annotation

    This is the Vendor class, where the XmlElement annotation sets the vendorID attribute as XmlID. Such key will match the reference set in Card class, using annotation XmlIDREF.
    package com.test.jaxb;
    
    import java.io.Serializable;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlID;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Vendor implements Serializable {
    	
    	 @XmlElement(name = "vendor-ID")
    	 @XmlID
    	private String vendorID;
    	 @XmlElement(name = "vendor-Name")
    	private String vendorName;
    	/**
    	 * @param vendorID
    	 * @param vendorName
    	 */
    	public Vendor(String vendorID, String vendorName) {
    		super();
    		this.vendorID = vendorID;
    		this.vendorName = vendorName;
    	}
    	/**
    	 * 
    	 */
    	public Vendor() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    	/**
    	 * @return the vendorID
    	 */
    	public String getVendorID() {
    		return vendorID;
    	}
    	/**
    	 * @param vendorID the vendorID to set
    	 */
    	public void setVendorID(String vendorID) {
    		this.vendorID = vendorID;
    	}
    	/**
    	 * @return the vendorName
    	 */
    	public String getVendorName() {
    		return vendorName;
    	}
    	/**
    	 * @param vendorName the vendorName to set
    	 */
    	public void setVendorName(String vendorName) {
    		this.vendorName = vendorName;
    	}
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "Vendor [vendorID=" + vendorID + ", vendorName=" + vendorName
    				+ "]";
    	}
    }
    

    public by cghersi modified Jul 27, 2013  338434  1  6  0

    ASP.NET Performance monitors

    The following XML file can be used to create a new user defined Data Collector Set in the Performance Monitor Tool for Windows servers. It checks the most important performance counters for the right execution of ASP.NET Web applications. The performance counters taken into account are those reported in this article: http://mvolo.com/fix-the-3-hi
    <?xml version="1.0" encoding="UTF-16"?>
    <DataCollectorSet>
    	<Status>0</Status>
    	<Duration>600</Duration>
    	<Description>Genera un rapporto con informazioni dettagliate sullo stato delle risorse hardware locali, sui tempi di risposta del sistema e sui processi eseguiti nel computer locale. Tali informazioni consentono di identificare le possibili cause dei problemi di prestazioni. Per eseguire questo Insieme agenti di raccolta dati, è necessario essere almeno membri del gruppo Administrators locale o di un gruppo equivalente.</Description>
    	<DescriptionUnresolved>Genera un rapporto con informazioni dettagliate sullo stato delle risorse hardware locali, sui tempi di risposta del sistema e sui processi eseguiti nel computer locale. Tali informazioni consentono di identificare le possibili cause dei problemi di prestazioni. Per eseguire questo Insieme agenti di raccolta dati, è necessario essere almeno membri del gruppo Administrators locale o di un gruppo equivalente.</DescriptionUnresolved>
    	<DisplayName>
    	</DisplayName>
    	<DisplayNameUnresolved>
    	</DisplayNameUnresolved>
    	<SchedulesEnabled>-1</SchedulesEnabled>
    	<Keyword>CPU</Keyword>
    	<Keyword>Memory</Keyword>
    	<Keyword>Disk</Keyword>
    	<Keyword>Network</Keyword>
    	<Keyword>Performance</Keyword>
    	<LatestOutputLocation>C:\PerfLogs\Admin\ASP.NET\ZIOJ-PC_20130727-000002</LatestOutputLocation>
    	<Name>ASP.NET</Name>
    	<OutputLocation>C:\PerfLogs\Admin\ASP.NET\ZIOJ-PC_20130727-000003</OutputLocation>
    	<RootPath>%systemdrive%\PerfLogs\Admin\ASP.NET</RootPath>
    	<Segment>0</Segment>
    	<SegmentMaxDuration>0</SegmentMaxDuration>
    	<SegmentMaxSize>0</SegmentMaxSize>
    	<SerialNumber>3</SerialNumber>
    	<Server>
    	</Server>
    	<Subdirectory>
    	</Subdirectory>
    	<SubdirectoryFormat>3</SubdirectoryFormat>
    	<SubdirectoryFormatPattern>yyyyMMdd\-NNNNNN</SubdirectoryFormatPattern>
    	<Task>
    	</Task>
    	<TaskRunAsSelf>0</TaskRunAsSelf>
    	<TaskArguments>
    	</TaskArguments>
    	<TaskUserTextArguments>
    	</TaskUserTextArguments>
    	<UserAccount>SYSTEM</UserAccount>
    	<Security>O:BAG:S-1-5-21-2577573897-3235701343-559641010-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;FR;;;LU)(A;;0x1301ff;;;S-1-5-80-2661322625-712705077-2999183737-3043590567-590698655)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200ab;;;LU)(A;ID;FR;;;AU)(A;ID;FR;;;LS)(A;ID;FR;;;NS)</Security>
    	<StopOnCompletion>0</StopOnCompletion>
    	<TraceDataCollector>
    		<DataCollectorType>1</DataCollectorType>
    		<Name>NT Kernel</Name>
    		<FileName>NtKernel</FileName>
    		<FileNameFormat>0</FileNameFormat>
    		<FileNameFormatPattern>
    		</FileNameFormatPattern>
    		<LogAppend>0</LogAppend>
    		<LogCircular>0</LogCircular>
    		<LogOverwrite>0</LogOverwrite>
    		<LatestOutputLocation>C:\PerfLogs\Admin\ASP.NET\ZIOJ-PC_20130727-000002\NtKernel.etl</LatestOutputLocation>
    		<Guid>{00000000-0000-0000-0000-000000000000}</Guid>
    		<BufferSize>64</BufferSize>
    		<BuffersLost>0</BuffersLost>
    		<BuffersWritten>0</BuffersWritten>
    		<ClockType>1</ClockType>
    		<EventsLost>0</EventsLost>
    		<ExtendedModes>0</ExtendedModes>
    		<FlushTimer>0</FlushTimer>
    		<FreeBuffers>0</FreeBuffers>
    		<MaximumBuffers>200</MaximumBuffers>
    		<MinimumBuffers>0</MinimumBuffers>
    		<NumberOfBuffers>0</NumberOfBuffers>
    		<PreallocateFile>0</PreallocateFile>
    		<ProcessMode>0</ProcessMode>
    		<RealTimeBuffersLost>0</RealTimeBuffersLost>
    		<SessionName>NT Kernel Logger</SessionName>
    		<SessionThreadId>0</SessionThreadId>
    		<StreamMode>1</StreamMode>
    		<TraceDataProvider>
    			<DisplayName>{9E814AAD-3204-11D2-9A82-006008A86939}</DisplayName>
    			<FilterEnabled>0</FilterEnabled>
    			<FilterType>0</FilterType>
    			<Level>
    				<Description>Gli eventi fino a questo livello sono attivati</Description>
    				<ValueMapType>1</ValueMapType>
    				<Value>0</Value>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x0</Value>
    				</ValueMapItem>
    			</Level>
    			<KeywordsAny>
    				<Description>Gli eventi con almeno una delle parole chiave specificate sono attivati</Description>
    				<ValueMapType>2</ValueMapType>
    				<Value>0x10303</Value>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x1</Value>
    				</ValueMapItem>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x2</Value>
    				</ValueMapItem>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x100</Value>
    				</ValueMapItem>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x200</Value>
    				</ValueMapItem>
    				<ValueMapItem>
    					<Key>
    					</Key>
    					<Description>
    					</Description>
    					<Enabled>-1</Enabled>
    					<Value>0x10000</Value>
    				</ValueMapItem>
    			</KeywordsAny>
    			<KeywordsAll>
    				<Description>Gli eventi con tutte le parole chiave specificate sono attivati</Description>
    				<ValueMapType>2</ValueMapType>
    				<Value>0x0</Value>
    			</KeywordsAll>
    			<Properties>
    				<Description>I campi dati aggiuntivi specificati verranno raccolti con ogni evento</Description>
    				<ValueMapType>2</ValueMapType>
    				<Value>0</Value>
    			</Properties>
    			<Guid>{9E814AAD-3204-11D2-9A82-006008A86939}</Guid>
    		</TraceDataProvider>
    	</TraceDataCollector>
    	<PerformanceCounterDataCollector>
    		<DataCollectorType>0</DataCollectorType>
    		<Name>Performance Counter</Name>
    		<FileName>Performance Counter</FileName>
    		<FileNameFormat>1</FileNameFormat>
    		<FileNameFormatPattern>yyyyMMdd</FileNameFormatPattern>
    		<LogAppend>-1</LogAppend>
    		<LogCircular>0</LogCircular>
    		<LogOverwrite>0</LogOverwrite>
    		<LatestOutputLocation>C:\PerfLogs\Admin\ASP.NET\ZIOJ-PC_20130727-000002\Performance Counter20130727.csv</LatestOutputLocation>
    		<DataSourceName>
    		</DataSourceName>
    		<SampleInterval>1</SampleInterval>
    		<SegmentMaxRecords>0</SegmentMaxRecords>
    		<LogFileFormat>0</LogFileFormat>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\% Managed Processor Time (estimated)</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Viewstate MAC Validation Failure</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Compilation</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Execution</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors During Preprocessing</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Unhandled During Execution</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Unhandled During Execution/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Audit Failure Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Infrastructure Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Infrastructure Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Request Error Events Raised</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Request Error Events Raised/Sec</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Total</Counter>
    		<Counter>\ASP.NET Apps v4.0.30319(__Total__)\Errors Total/Sec</Counter>
    		<Counter>\ASP.NET v4.0.30319\Error Events Raised</Counter>
    		<Counter>\ASP.NET v4.0.30319\Infrastructure Error Events Raised</Counter>
    		<Counter>\ASP.NET v4.0.30319\Request Error Events Raised</Counter>
    		<Counter>\.NET CLR Exceptions\*</Counter>
    		<Counter>\.NET CLR Memory(_Global_)\% Time in GC</Counter>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\% Tempo processore gestito (stimato)</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errore di convalida MAC ViewState</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di compilazione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di esecuzione.</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori di pre-elaborazione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori non gestiti durante l'esecuzione</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Errori non gestiti durante l'esecuzione/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore di controllo generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore infrastruttura generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore infrastruttura generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore richiesta generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Eventi errore richiesta generati/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Totale errori</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET Apps v4.0.30319(__Total__)\Totale errori/sec</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore infrastruttura generati</CounterDisplayName>
    		<CounterDisplayName>\ASP.NET v4.0.30319\Eventi errore richiesta generati</CounterDisplayName>
    		<CounterDisplayName>\Eccezioni CLR .NET\*</CounterDisplayName>
    		<CounterDisplayName>\Memoria CLR .NET(_Global_)\Percentuale tempo in GC</CounterDisplayName>
    	</PerformanceCounterDataCollector>
    	<DataManager>
    		<Enabled>-1</Enabled>
    		<CheckBeforeRunning>-1</CheckBeforeRunning>
    		<MinFreeDisk>200</MinFreeDisk>
    		<MaxSize>1024</MaxSize>
    		<MaxFolderCount>100</MaxFolderCount>
    		<ResourcePolicy>0</ResourcePolicy>
    		<ReportFileName>report.html</ReportFileName>
    		<RuleTargetFileName>report.xml</RuleTargetFileName>
    		<EventsFileName>
    		</EventsFileName>
    		<Rules>
    			<Logging level="15" file="rules.log">
    			</Logging>
    			<Import file="%systemroot%\pla\rules\Rules.System.Common.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.Summary.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.Performance.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.CPU.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.Network.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.Disk.xml">
    			</Import>
    			<Import file="%systemroot%\pla\rules\Rules.System.Memory.xml">
    			</Import>
    		</Rules>
    		<ReportSchema>
    			<Report name="systemPerformance" version="1" threshold="100">
    				<Import file="%systemroot%\pla\reports\Report.System.Common.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.Summary.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.Performance.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.CPU.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.Network.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.Disk.xml">
    				</Import>
    				<Import file="%systemroot%\pla\reports\Report.System.Memory.xml">
    				</Import>
    			</Report>
    		</ReportSchema>
    		<FolderAction>
    			<Size>0</Size>
    			<Age>1</Age>
    			<Actions>3</Actions>
    			<SendCabTo>
    			</SendCabTo>
    		</FolderAction>
    		<FolderAction>
    			<Size>0</Size>
    			<Age>56</Age>
    			<Actions>8</Actions>
    			<SendCabTo>
    			</SendCabTo>
    		</FolderAction>
    		<FolderAction>
    			<Size>0</Size>
    			<Age>168</Age>
    			<Actions>26</Actions>
    			<SendCabTo>
    			</SendCabTo>
    		</FolderAction>
    	</DataManager>
    	<Value name="PerformanceMonitorView" type="document">
    		<OBJECT ID="DISystemMonitor" CLASSID="CLSID:C4D2D8E0-D1DD-11CE-940F-008029004347">
    			<PARAM NAME="CounterCount" VALUE="4">
    			</PARAM>
    			<PARAM NAME="Counter00001.Path" VALUE="\Processor(_Total)\% Processor Time">
    			</PARAM>
    			<PARAM NAME="Counter00001.Color" VALUE="255">
    			</PARAM>
    			<PARAM NAME="Counter00001.Width" VALUE="2">
    			</PARAM>
    			<PARAM NAME="Counter00001.LineStyle" VALUE="0">
    			</PARAM>
    			<PARAM NAME="Counter00001.ScaleFactor" VALUE="0">
    			</PARAM>
    			<PARAM NAME="Counter00001.Show" VALUE="1">
    			</PARAM>
    			<PARAM NAME="Counter00001.Selected" VALUE="1">
    			</PARAM>
    			<PARAM NAME="Counter00002.Path" VALUE="\Memory\Pages/sec">
    			</PARAM>
    			<PARAM NAME="Counter00002.Color" VALUE="65280">
    			</PARAM>
    			<PARAM NAME="Counter00002.Width" VALUE="1">
    			</PARAM>
    			<PARAM NAME="Counter00003.Path" VALUE="\PhysicalDisk(_Total)\Avg. Disk sec/Read">
    			</PARAM>
    			<PARAM NAME="Counter00003.Color" VALUE="16711680">
    			</PARAM>
    			<PARAM NAME="Counter00003.Width" VALUE="1">
    			</PARAM>
    			<PARAM NAME="Counter00004.Path" VALUE="\PhysicalDisk(_Total)\Avg. Disk sec/Write">
    			</PARAM>
    			<PARAM NAME="Counter00004.Color" VALUE="55295">
    			</PARAM>
    			<PARAM NAME="Counter00004.Width" VALUE="1">
    			</PARAM>
    		</OBJECT>
    	</Value>
    </DataCollectorSet>
    

    public by bojan.hrnkas modified Jan 22, 2013  224936  0  7  0

    Serializing a C# object to XML

    We use a simplified object WSCustomer, since we only want some members of Customer to get serialized.
    public string GetCustomerData(int customers_Id)
    {
        Customer customers = IoC.Resolve<ICustomerService>().GetCustomerById(customers_Id);
        WSCustomer wsCustomer = WSMapping(customers);
        StringBuilder sb = new StringBuilder();
        using (TextWriter tw = new StringWriter(sb))
        {
            XmlSerializer xmlS = new XmlSerializer(typeof(WSCustomer));
            xmlS.Serialize(tw, wsCustomer);
            string serialized = sb.ToString();
            return serialized;
        }
    }
    
    

    public by dfgdfgdfg modified May 12, 2014  156030  0  5  -4

    test create xml

    xml
    //create xml file:
    //hello test.

    public by lbottaro modified Mar 31, 2014  3678  0  7  2

    MyNetwork class - Java example for marshalling/unmarshalling object to xml using JAX-B

    This is the main class of the previous example. MyNetwork contains two lists, one for Equipment class and one for Vendor class. Since it's the main root of the xml, I set the annotation XmlRootElement, with value = network-topology. Such name will be displayed in the xml. @XmlType annotation sets the order of the attributes in the xml, using prop
    package com.test.jaxb;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlElementWrapper;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlRootElement(name = "network-topology")
    @XmlType(propOrder={"vendors", "equipments"})
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class MyNetwork {
    
    	@XmlElementWrapper(name = "equipments-list")
        @XmlElement(name = "equipment")
        private List<Equipment> equipments;
    	
        @XmlElementWrapper(name = "vendors-list")
        @XmlElement(name = "vendor")
        private List<Vendor> vendors;
    
        /**
    	 * @return the vendors
    	 */
    	public List<Vendor> getVendors() {
    		return vendors;
    	}
    
    	/**
    	 * @param vendors the vendors to set
    	 */
    	public void setVendors(List<Vendor> vendors) {
    		this.vendors = vendors;
    	}
    
    	/**
    	 * @return the equipments
    	 */
    	public List<Equipment> getEquipments() {
    		return equipments;
    	}
    
    	/**
    	 * @param equipments the equipments to set
    	 */
    	public void setEquipments(List<Equipment> equipments) {
    		this.equipments = equipments;
    	}
    
    	/**
    	 * @param eqp the equipment to add 
    	 */
    	public void addEquipments(Equipment eqp) {
            if (equipments == null) {
                this.equipments = new ArrayList();
            }
            equipments.add(eqp);
        }
    	
    	/**
    	 * @param vendor the equipment to add 
    	 */
    	public void addVendor(Vendor vendor) {
            if (vendors == null) {
                this.vendors = new ArrayList();
            }
            vendors.add(vendor);
        }
    }
    
    

    public by cghersi modified Jun 2, 2014  184998  1  6  1

    Use the Raw HTML content in XSLT transformations

    Usage of copy-of element allows to get the exact content of an XML node and put it as raw HTML, so that e.g. are not stripped out as instead happens with
    <myXmlNode>
    	<question>
    	Some text <br/> separated < br/> by new lines
    	</question>
    </myXmlNode>
    
    <span>
    	<xsl:copy-of select="question"/>
    </span>

    public by lbottaro modified Mar 31, 2014  3898  0  8  5

    Card class - Example for marshalling/unmarshalling java object using JAX-B

    Finally this is the Card class. It's used the standard JAX-B annotations for specifying the XmlElement and the XmlAccessorType. Note the usage of XmlAttribute annotation to specify the Vendor ID as attribute of element Card. Moreover the XmlIDREF annotation will link the attribute vendor with the ID of Vendor class. In this way once the xml will b
    package com.test.jaxb;
    
    import java.io.Serializable;
    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.XmlIDREF;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Card implements Serializable {
    
    	@XmlElement
        private CardType type;
    	@XmlElement
        private String number;
    	@XmlElement
        private int numOfSlots;
    	@XmlAttribute
        @XmlIDREF
        private Vendor vendor;
    
        /**
    	 * @return the vendor
    	 */
    	public Vendor getVendor() {
    		return vendor;
    	}
    
    	/**
    	 * @param vendor the vendor to set
    	 */
    	public void setVendor(Vendor vendor) {
    		this.vendor = vendor;
    	}
    
    	public Card() {
        }
    
    	/**
    	 * @return the type
    	 */
    	public CardType getType() {
    		return type;
    	}
    
    	/**
    	 * @param type the type to set
    	 */
    	public void setType(CardType type) {
    		this.type = type;
    	}
    
    	/**
    	 * @return the number
    	 */
    	public String getNumber() {
    		return number;
    	}
    
    	/**
    	 * @param number the number to set
    	 */
    	public void setNumber(String number) {
    		this.number = number;
    	}
    
    	/**
    	 * @return the numOfSlots
    	 */
    	public int getNumOfSlots() {
    		return numOfSlots;
    	}
    
    	/**
    	 * @param numOfSlots the numOfSlots to set
    	 */
    	public void setNumOfSlots(int numOfSlots) {
    		this.numOfSlots = numOfSlots;
    	}
    
    	/**
    	 * @param type
    	 * @param number
    	 * @param numOfSlots
    	 */
    	public Card(CardType type, String number, int numOfSlots, Vendor vendor) {
    		super();
    		this.type = type;
    		this.number = number;
    		this.numOfSlots = numOfSlots;
    		this.vendor=vendor;
    	}
    
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "Card [type=" + type + ", number=" + number + ", numOfSlots="
    				+ numOfSlots + ", vendor=" +vendor+"]";
    	}
    }
    

    public by lbottaro modified Mar 31, 2014  5068  1  9  4

    How to marshal and unmarshal java class to xml file using JAX-B

    This java code shows how to marshal and unmarshal class data to xml using JAX-B library, contained in javax.xml.bind.JAXB package. MyNetwork object contains two lists, one for Vendor objects and one for Equipment objects. Each Equipment has a list of Cards and each card refers to a specific Vendor. Marshalling and unmarshalling operation is dele
    package com.test.jaxb;
    
    import java.io.File;
    import javax.xml.bind.JAXB;
    
    public class MarshallingExamples {
    
        public MarshallingExamples() {
            MyNetwork network = new MyNetwork();
            Vendor v1 = new Vendor("123", "NameVVV");
            Vendor v2 = new Vendor("567", "NameZZZ");
            Vendor v3 = new Vendor("345", "NameXXX");
            Equipment eqp1 = new Equipment("112233", "TYPE_ABC", "00-14-22-01-23-45");
            eqp1.addCard(new Card(CardType.DWDM, "AABBCC", 2, v1));
            network.addEquipments(eqp1);
            Equipment eqp2 = new Equipment("222333", "TYPE_ZZZ", "00-C4-22-C1-23-C5");
            eqp2.addCard(new Card(CardType.SDH, "AA1234", 1, v2));
            eqp2.addCard(new Card(CardType.ETH, "AACCDD", 4, v1));
            network.addEquipments(eqp2);
            Equipment eqp3 = new Equipment("445566", "TYPE_CDE", "01-C3-2A-C1-AA-C5");
            eqp3.addCard(new Card(CardType.DWDM, "AAFF44", 1, v3));
            eqp3.addCard(new Card(CardType.DWDM, "AABF33", 1, v3));
            eqp3.addCard(new Card(CardType.ETH, "AA33DD", 2, v2));
            network.addEquipments(eqp3);
            network.addVendor(v1);
            network.addVendor(v2);
            network.addVendor(v3);
            JAXB.marshal(network, new File("out.xml"));        
            network = JAXB.unmarshal(new File("out.xml"), MyNetwork.class);
            for(Equipment eqp : network.getEquipments()) {
                System.out.println(eqp);
            }
            for(Vendor vend : network.getVendors()) {
                System.out.println(vend);
            }
        }
    
        public static void main(String[] args) {
            new MarshallingExamples();
        }
    }
    

    public by qxshower modified Apr 27, 2015  87225  1  5  0

    CreateXmlCloseTag

    Creates the XML close tag string for an XElement.
    using EnvDTE;
    using SteveCadwallader.CodeMaid.Model.Comments;
    using System.Diagnostics;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Creates the XML close tag string for an XElement.
    /// </summary>
    /// <param name="element">The element.</param>
    /// <param name="options">The comment options used to contruct the tag.</param>
    /// <returns>
    /// The XML close tag, or <c>null</c> if the element has no value and is a self-closing tag.
    /// </returns>
    internal static string CreateXmlCloseTag(System.Xml.Linq.XElement element, CodeCommentOptions options)
    {
        if (element.IsEmpty)
        {
            return null;
        }
    
        var name = element.Name.LocalName;
    
        var result = string.Format("</{0}>", options.XmlTagsToLowerCase ? name.ToLowerInvariant() : name);
    
        return options.XmlKeepTagsTogether ? SpaceToFake(result) : result;
    }                        

    public by lbottaro modified Mar 31, 2014  2953  1  7  2

    Equipment class - Example for marshalling/unmarshalling java object using JAX-B

    This is the Equipment class. You can see the usage of Jax-B XmlElement and XmlElementWrapper annotations to define xml attributes and wrapper attribute.
    package com.test.jaxb;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlElementWrapper;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlType(propOrder = {"eqpID", "macAddress", "type", "cards"})
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Equipment implements Serializable {
    
        @XmlElement(name = "equipment-ID")
        private String eqpID;
        @XmlElement(name = "equipment-type")
        private String type;
        @XmlElement(name = "equipment-mac-address")
        private String macAddress;
        @XmlElementWrapper(name = "cards")
        @XmlElement(name = "traffic-card")
        private List<Card> cards; 
    
        public Equipment() {
        }
        
    	/**
    	 * @param eqpID
    	 * @param type
    	 * @param macAddress
    	 */
    	public Equipment(String eqpID, String type, String macAddress) {
    		super();
    		this.eqpID = eqpID;
    		this.type = type;
    		this.macAddress = macAddress;
    	}    
    
    	/**
    	 * @param eqpID
    	 * @param type
    	 * @param macAddress
    	 * @param cards
    	 */
    	public Equipment(String eqpID, String type, String macAddress,
    			List<Card> cards) {
    		super();
    		this.eqpID = eqpID;
    		this.type = type;
    		this.macAddress = macAddress;
    		this.cards = cards;
    	}
    	
    	/**
    	 * @return the eqpID
    	 */
    	public String getEqpID() {
    		return eqpID;
    	}
    
    	/**
    	 * @param eqpID the eqpID to set
    	 */
    	public void setEqpID(String eqpID) {
    		this.eqpID = eqpID;
    	}
    
    	/**
    	 * @return the type
    	 */
    	public String getType() {
    		return type;
    	}
    
    	/**
    	 * @param type the type to set
    	 */
    	public void setType(String type) {
    		this.type = type;
    	}
    
    	/**
    	 * @return the macAddress
    	 */
    	public String getMacAddress() {
    		return macAddress;
    	}
    
    	/**
    	 * @param macAddress the macAddress to set
    	 */
    	public void setMacAddress(String macAddress) {
    		this.macAddress = macAddress;
    	}
    
    	/**
    	 * @return the cards
    	 */
    	public List<Card> getCards() {
    		return cards;
    	}
    
    	/**
    	 * @param cards the cards to set
    	 */
    	public void setCards(List<Card> cards) {
    		this.cards = cards;
    	}
        
    	/**
    	 * @param card the equipment to add 
    	 */
    	public void addCard(Card card) {
            if (cards == null) {
                this.cards = new ArrayList();
            }
            cards.add(card);
        }
    
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "Equipment [eqpID=" + eqpID + ", type=" + type + ", macAddress="
    				+ macAddress + ", cards=" + cards + "]";
    	}
    }
    
    • Public Snippets
    • Channels Snippets