XML namespaces and attributes

Most of the time, attributes will not be in any namespace. The namespace spec says (emphasis mine): A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. There’s … Read more

JAXB: How to change XJC-generated classes names when attr type is specified in XSD?

JAXB provides two ways to accomplish this: 1. Inline Schema Anntotations You can use JAXB schema annotations to control the class names. <xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema” xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” jaxb:version=”2.1″> <xs:complexType name=”itemType”> <xs:annotation> <xs:appinfo> <jaxb:class name=”Item”/> </xs:appinfo> </xs:annotation> <xs:attribute name=”id” type=”xs:string” use=”required”/> </xs:complexType> </xs:schema> 2. External Binding File This customization can also be done via and external binding file: … Read more

Multiple XSD schema files to C# classes

Use the XSD.EXE program, but pass all of the schemas to the program on the same command line. For example: > xsd /c qbxmltypes130.xsd QBUqbxmlops130.xsd QBUqbxmlso130.xsd QBUqbxml130.xsd Will emit a class named: qbxmltypes130_QBUqbxmlops130_QBUqbxmlso130_QBUqbxml130.cs In this case these are Quickbooks Desktop SDK xsd files, and the final file has types it depends on in the first … Read more

XSD element with both attributes and child elements

This is one possible way to define an XSD matching your XML; when learning XSD, you could enroll the help of a tool that infers the XSD for you, starting from one or more XML sample files. <?xml version=”1.0″ encoding=”utf-8″?> <!–W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)–> <xsd:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”component”> … Read more

Is it possible to generate a XSD from a JAXB-annotated class?

Yes, you can use the generateSchema method on JAXBContext: JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); SchemaOutputResolver sor = new MySchemaOutputResolver(); jaxbContext.generateSchema(sor); You leverage an implementation of SchemaOutputResolver to control where the output goes: public class MySchemaOutputResolver extends SchemaOutputResolver { public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { File file = new File(suggestedFileName); StreamResult result = new … Read more

How to choose between DTD and XSD

It’s probably important to learn DTDs as a separate exercise, just for the knowledge of how they work in case you encounter them somewhere else, and so that you can appreciate some of the things that XSD was trying to solve. However, for your current purposes of describing an XML document, indeed stick to XSDs. … Read more

Unable to generate a temporary class (result=1). error CS0030: Cannot convert type ‘Type[]’ to ‘Type’?

You need to change the type of a member variable in the serialized class. For example if its raising an error like: Unable to generate a temporary class (result=1). error CS0030: Cannot convert type ‘Data[]’ to ‘Data’. I ran a search on the Data type name in the generated file, and I found this: [System.Xml.Serialization.XmlArrayItemAttribute(“Data”, … Read more

Troubles with WADL / generated XSD using Jersey with a contract-first approach

1.14-SNAPSHOT should allow you to do this: public class SampleWadlGeneratorConfig extends WadlGeneratorConfig { @Override public List<WadlGeneratorDescription> configure() { return generator( WadlGeneratorApplicationDoc.class ) .prop( “applicationDocsStream”, “application-doc.xml” ) .generator( WadlGeneratorGrammarsSupport.class ) .prop( “grammarsStream”, “application-grammars.xml” ) .prop(“overrideGrammars”, true) // !!! .generator( WadlGeneratorResourceDocSupport.class ) .prop( “resourceDocStream”, “resourcedoc.xml” ) .descriptions(); } } when overrideGrammars is set to true, Jersey generated … Read more

Generating a JAXB class that implements an interface

Unfortunately, it looks like the interface-injection plugin mentioned in some of the other answers is no longer well-supported. In fact, I’m having trouble finding the JAR for download. Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin). The Inheritance plugin documentation has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)