JAXB parse of Atom.xsd produces validation errors - xsd

I am seeking to use JAXB to parse the Atom feed coming back from invoking Sharepoint 2010's REST service, and having the JAXB bind and compile happen on build in eclipse. I downloaded a couple different versions of the atom xsd I found online (they differ only in some header attributes), including this one (http://www.kbcafe.com/rss/atom.xsd.xml) but am CONSISTENTLY getting the following errors regardless of which I use:
[xjc] [WARNING] schema_reference.4: Failed to read schema document 'http://www.w3.org/2001/03/xml.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
[xjc] line 14 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd
[xjc] [ERROR] src-resolve: Cannot resolve the name 'xml:base' to a(n) 'attribute declaration' component.
[xjc] line 292 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd
[xjc] [ERROR] s4s-elt-must-match.1: The content of 'commonAttributes' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attribute.
[xjc] line 292 of file:/C:/rest_workspace/eDocs/src/gov/afms/edocs/rest/jaxb/schemas/AtomSchema2.xsd
I have seen some comments saying taht Java5 Xerces had some issues, but I echo out my java version from my ant script and am using 1.6. The node at line 14 is:
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd" />
The node at line 292 is:
<xs:attribute ref="xml:base" />
Note that eclipse is also flagging these things as errors. For the warning, eclipse says "XSD: The location 'http://www.w3.org/2001/03/xml.xsd' has not been resolved", for the error line it says "XSD: Attribute reference 'http://www.w3.org/XML/1998/namespace#base' is unresolved". It also errors on 293 which is similar to the above but pointing at lang instead of base.
It's wierd to me that the parser is trying to resolve the reference to the namespace document since that appears to be just an HTML doc explaining namespaces, NOT an XSD or DTD. But this Atomschema2.xsd isn't something I made up, it was downloaded.
What am I supposed to be doing here? Is there a better atom schema? Should I modify the schema I downloaded to chage the references? Some third thing?

The error is typically caused by the DTD DOCTYPE on top of the xml.xsd file; I never tried to figure it out with JAXB, but I can guarantee that if you download, fix the references, and remove the <!DOCTYPE...[]> from the xml.xsd file, JAXB will work out of the box with the schema you pointed at (I just tried it in NetBeans 7.1 with no issues). I guess a good question now is how to get JAXB's xjc to ignore the DTD...
UPDATE: -catalog in the command line might do it, please read this.

Related

Trouble Compiling Apache POI 5.2.2 Code - Factory.newInstance() methods

Apache POI newbie.
I am trying to use Apache POI 5.2.2 to generate footnotes in a Word document.
There are some useful SO posts on this topic:
Need to add a footnote in between texts and the next text should be appeared in the same line not in the next line in Apache poi
Need to insert the text at the end of the page but the table is still continuing in the next page
However, when I try to run those examples, I get very consistent errors on these 3 Factory.newInstance() methods:
CTFtnEdn.Factory.newInstance();
CTStyle.Factory.newInstance();
CTDecimalNumber.Factory.newInstance();
The compiler says: "error: incompatible types: XmlObject cannot be converted to" either CTFtnEdn, CTStyle or CTDecimalNumber, as applicable.
Here is the full compilation error for one of these, but all 3 are similar:
Footnotes.java:68: error: incompatible types: XmlObject cannot be converted to CTFtnEdn
CTFtnEdn ctfInstance = CTFtnEdn.Factory.newInstance();
poi-ooxml-full-5.2.2.jar is included in the compilation classpath.
I assume I have not included one or more jar files needed to get this working.
Any ideas how to get this working?
I believe I had conflicting jar files in the classpath. Removing one has fixed the issue. Axel Richter, thanks for helping me identify that.

PostSharp warnings when using fakes in VS2012

We've updated to VS2012 recently and also changed our PostSharp version to 3.0.26. Generally this combination works fine, but I get warnings for my unit test project such as
The module "MyModule.Fakes.dll" does not contain any aspect or other transformation. For improved build-time performance, consider disabling PostSharp for this module by setting the compilation symbol (aka constant) "SkipPostSharp" in your project or set the MSBuild property "SkipPostSharp=True".
Now usually I can disable this warning by changing the project settings accordingly (SkipPostSharp = True), but I've already done that for my MyProjectTest project containing the unit tests.
When I add <SkipPostSharp>True</SkipPostSharp> to my MyModule.Fakes file in the Fakes folder, the warning about PostSharp disappears, however, I get another error message:
The element "Fakes" in namespace "http://schemas.microsoft.com/fakes/2011/" has invalid child element "SkipPostSharp" in namespace "http://schemas.microsoft.com/fakes/2011/". List of possible elements expected: "StubGeneration, ShimGeneration, Compilation" in namespace "http://schemas.microsoft.com/fakes/2011".
Update
I also tried editing the fakes.xsd file and add an extra SkipPostSharp element, but a) this still isn't recognised as a valid element by Visual Studio and b) I'm not sure whether this would be the right approach anyway.
Any ideas how to get rid of these warnings?
You can specify additional properties for the project file Fakes will generate to build the fakes assembly by placing Property elements inside of the Compilation element at the end of the .FAKES file. Here is an example based on your description.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="MyModule"/>
<Compilation>
<Property Name="SkipPostSharp">True</Property>
</Compilation>
</Fakes>

avoid generating a jaxb enum class for this simpleType...(or use string instead)

We have a 10,000 enum that someone put in the xsd which generates a 60,000 line file in java which can't compile saying the code is too large
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project framework: Compilation failure
[ERROR] /Users/dhiller/Space/ifp-core/framework/target/generated-sources/com/framework/util/LanguageCodeSimpleType.java:[7627,4] code too large
Anyway in jaxb to either
Map the simpletype to a String to generate strings all over the place
just exclude the element as I don't think people are using it
(I may just remove it from the schema and see if people complain or not)
This could help - the enum class is not generated any more.
<jaxb:typesafeEnumClass map="false" />
How to avoid mapping to enum class

JAXB : use local schemaLocation to generate Java classes

I am trying to generate Java classes from a XSD schema using the xjc command that comes with JAXB.
My schema looks like:
<xs:schema xmlns="..."
xmlns:ext="http://schemas.myco.com/ext" ... >
<xs:import namespace="http://schemas.myco.com/ext"
schemaLocation="http://myco.com/schemas/ext.xsd"/>
...
The problem is that the schemaLocation URI does not exist and I can not modify the XSD file. That is why the generation process fails with errors such as "src-resolve: Cannot resolve the name 'ext:Resource_Type' to a(n) 'type definition' component".
Is there any way to force JAXB to use a local copy of ext.xsd file during the process without modifying the original XSD file ?
Two possible solutions:
JAXB Episode File:
http://weblogs.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21
or
XML Catalogs (search Google)

Compile errors with subsonic 3.0 activerecord?

Note, I have used subsonic 2.2 extensively and love it. This is my first experience with 3.0.
I want to add subsonic to my class library rather than the website. First when I do this, and try and run the custom tool to compile the template files, I get errors saying there is not app.config file. In subsonic 2, I was able to do this and point it to my web.config file. So first question is can I use the web.config file when adding subsonic to an external class library?
The second thing that I'm experiencing are 44 identical compile errors.
This is the error from VS 2008:
Error 44 'krazyCommon.model.atDB' does not contain a definition for 'Provider' and no extension method 'Provider' accepting a first argument of type 'krazyCommon.model.atDB' could be found (are you missing a using directive or an assembly reference?) C:\dev\krazybuys\krazyCommon\model\StoredProcedures.cs 175 100 krazyCommon
and this is the code that is causing it. The end of the line this.Provider is where the error is being caused. In VS it has a squiggly line under it.
public StoredProcedure aspnet_UsersInRoles_RemoveUsersFromRoles(){
StoredProcedure sp=new StoredProcedure("aspnet_UsersInRoles_RemoveUsersFromRoles",this.Provider);
return sp;
}
I'm perplexed as I think I'm doing everything correct. Any help would be appreciated.
Many Thanks.
Update, I did find the cause of the compile error. I changed the namespace in the settings file. However, the namespace did not update in the storedprocedure.tt output. It does change for activerecord and content, but not storedprocedures. I manually changed the namespace and it compiled without error.
Is this a bug in the template or subsonic?
Is it possible to change the namespace in settings? And if so, should subsonic pick that up if you right click on activerecord, content and storedprocedures and "Run custom tool" again.
Thanks
Sorry I forgot to add that I did add an app.config file to the class library and added a conn string before I got the 44 errors.

Resources