Preguntas y respuestas de entrevista mas solicitadas y pruebas en linea
Plataforma educativa para preparacion de entrevistas, pruebas en linea, tutoriales y practica en vivo

Desarrolla tus habilidades con rutas de aprendizaje enfocadas, examenes de practica y contenido listo para entrevistas.

WithoutBook reune preguntas de entrevista por tema, pruebas practicas en linea, tutoriales y guias comparativas en un espacio de aprendizaje responsivo.

Preparar entrevista

JAXB preguntas y respuestas de entrevista

Pregunta 11. Java code for marshalling Java objects into XML.

β€’ Example
Marshaller m = factory.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer fw = new FileWriter("newCars.xml");
m.marshal(cars, fw);
β€’ marshal method accepts
– java.io.OutputStream
– java.io.Writer
– javax.xml.transform.Result
β€’ related to XSLT
– org.w3c.dom.Node
β€’ related to DOM
– org.xml.sax.ContentHandler
β€’ related to SAX

β€’ Other Marshaller methods
– boolean setEventHandler(ValidationEventHandler handler)
β€’ same as use with Unmarshaller, but validation events
are delivered during marshalling
– void setProperty(String name, Object value)
β€’ supported properties are
– jaxb.encoding - value is a String
Β» the encoding to use when marshalling; defaults to β€œUTF-8”
– jaxb.formatted.output - value is a Boolean
Β» true to output line breaks and indentation; false to omit (the default)
– jaxb.schemaLocation - value is a String
Β» to specify xsi:schemaLocation attribute in generated XML
– jaxb.noNamespaceSchemaLocation - value is a String
Β» to specify xsi:noNamespaceSchemaLocation attribute in generated XML

Es util? Agregar comentario Ver comentarios
 

Pregunta 12. Java example/java program to set object for generating XML.

Cars cars = factory.createCars();
Car car = factory.createCar();
car.setColor("blue");
car.setMake("Mazda");
car.setModel("Miata");
car.setYear(BigInteger.valueOf(2012));
cars.getCar().add(car);
car = factory.createCar();
car.setColor("red");
car.setMake("Ford");
car.setModel("Mustang II");
car.setYear(BigInteger.valueOf(2011));
cars.getCar().add(car);

Es util? Agregar comentario Ver comentarios
 

Pregunta 13. How to validate java objects?

β€’ The graph of Java objects can contain invalid data
– could occur when objects created by unmarshalling are modified
– could occur when objects are created from scratch
β€’ Use a Validator to validate the objects
β€’ Example
Validator v = factory.createValidator();
try {
v.validateRoot(cars);
v.validate(car);
} catch (ValidationException e) {
// Handle the validation error described by e.getMessage().
}

β€’ Other Validator methods
– boolean setEventHandler(ValidationEventHandler handler)
β€’ handleEvent method of ValidationEventHandler is called
if validation errors are encountered
β€’ default handler terminates marshalling after first error
β€’ return true to continue validating
β€’ return false to terminate with ValidationException

Pass an instance of javax.xml.bind.util.ValidationEventCollector
(in jaxb-api.jar) to setEventHandler to collect validation errors and
query them later instead of handling them during validation.
ValidationEventCollector vec =
new ValidationEventCollector();
v.setEventHandler(vec);
v.validate(cars);
ValidationEvent[] events = vec.getEvents();

Es util? Agregar comentario Ver comentarios
 

Pregunta 14. Customizing Type Bindings.

β€’ Default bindings can be overridden
– at global scope
– on case-by-case basis
β€’ Customizations include
– names of generated package, classes and methods
– method return types
– class property (field) types
– which elements are bound to classes, as opposed to being ignored
– class property to which each attribute and element declaration is bound

Es util? Agregar comentario Ver comentarios
 

Pregunta 15. Syntax of customization.

β€’ Customizations can be specified in
– the XML Schema (our focus)
– a binding declarations XML document (not well supported by RI yet)
β€’ The XML Schema must declare
the JAXB namespace and version
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema”
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
β€’ Customization elements are placed in annotation elements
<xsd:annotation>
<xsd:appinfo>
binding declarations
</xsd:appinfo>
</xsd:annotation>

Es util? Agregar comentario Ver comentarios
 

Lo mas util segun los usuarios:

Copyright Β© 2026, WithoutBook.