Ha! Yep, that fixed it. Thanks.
On Mon, 2010-08-30 at 09:51 -0400, Duane Zamrok wrote:
> You're attempting to parse "junk.xml" not new File("junk.xml"). That is,
> you're attempting to parse the file name and not the file.
>
> -Duane
>
> -----Original Message-----
> From: Tim Watts [mailto:[email protected]]
> Sent: Monday, August 30, 2010 7:31 AM
> To: [email protected]
> Subject: parse fails on doc xmlbeans just saved
>
> I'm having trouble figuring out why xmlbeans fails to parse the xml doc
> it just saved. It's a fairly simple setup: create a doc; save it; read
> it back. Can anyone see what I'm doing wrong? I'm using version 2.5.0
> running under sun java 6 on Linux.
>
> (BTW, it fails the same way whether or not I use pretty print)
>
> OUTPUT
> ---------------
> ----------------- WRITING XML DOC:
> <sch:Config xmlns:sch="http://scrapbook.org/schema">
> <sch:host>myhost.org</sch:host>
> <sch:username>tim</sch:username>
> <sch:password>bXlwYXNzd29yZA==</sch:password>
> <sch:system>dev</sch:system>
> <sch:wildcard>true</sch:wildcard>
> <sch:offline>false</sch:offline>
> </sch:Config>
>
> ----------------- READING XML DOC:
> org.apache.xmlbeans.XmlException: /home/timtw/work/junk.xml:1:1: error:
> Unexpected element: CDATA
> at org.apache.xmlbeans.impl.store.Locale
> $SaxLoader.load(Locale.java:3486)
> at org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:712)
> at
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:696)
> at
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:683)
> at
> org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:208)
> at org.scrapbook.schema.ConfigDocument
> $Factory.parse(ConfigDocument.java:202)
> at org.scrapbook.XbeanFun.run(XbeanFun.java:79)
> at org.scrapbook.XbeanFun.main(XbeanFun.java:48)
> Caused by: org.xml.sax.SAXParseException: Unexpected element: CDATA
> at
> org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038)
> at
> org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723)
> at org.apache.xmlbeans.impl.store.Locale
> $SaxLoader.load(Locale.java:3454)
> ... 7 more
>
> SCHEMA
> ---------------
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://scrapbook.org/schema"
> xmlns:tns="http://scrapbook.org/schema"
> elementFormDefault="qualified">
> <element name="Config">
> <complexType>
> <sequence>
> <element name="host" maxOccurs="1" type="string"/>
> <element name="username" maxOccurs="1" type="NMTOKEN"/>
> <element name="password" maxOccurs="1" type="base64Binary"/>
> <element name="system" maxOccurs="1" type="tns:system"/>
> <element name="wildcard" maxOccurs="1" type="boolean"/>
> <element name="offline" maxOccurs="1" type="boolean"/>
> </sequence>
> </complexType>
> </element>
> <simpleType name="system">
> <restriction base="string">
> <enumeration value="prod"/>
> <enumeration value="test"/>
> <enumeration value="dev"/>
> </restriction>
> </simpleType>
> </schema>
>
> XML DOC
> ---------------
> <?xml version="1.0" encoding="UTF-8"?>
> <sch:Config xmlns:sch="http://scrapbook.org/schema">
> <sch:host>myhost.org</sch:host>
> <sch:username>tim</sch:username>
> <sch:password>bXlwYXNzd29yZA==</sch:password>
> <sch:system>dev</sch:system>
> <sch:wildcard>true</sch:wildcard>
> <sch:offline>false</sch:offline>
> </sch:Config>
>
> SOURCE CODE
> ---------------
> package org.scrapbook;
>
> import java.io.File;
> import java.io.IOException;
> import java.io.PrintStream;
> import java.lang.reflect.Method;
> import java.util.List;
>
> import org.apache.xmlbeans.XmlException;
> import org.apache.xmlbeans.XmlOptions;
> import org.scrapbook.schema.ConfigDocument;
> import org.scrapbook.schema.ConfigDocument.Config;
> import org.scrapbook.schema.System;
>
>
> public class XbeanFun {
>
> public static PrintStream out = java.lang.System.out;
>
> public static void main(String[] args) {
> try {
> new XbeanFun().run();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public void run() {
> try {
> ConfigDocument cdoc = ConfigDocument.Factory.newInstance();
> Config config = cdoc.addNewConfig();
>
> config.setHost("myhost.org");
> config.setOffline(false);
> config.setSystem(System.DEV);
> config.setUsername("tim");
> config.setPassword("mypassword".getBytes());
> config.setWildcard(true);
>
> out.println("----------------- WRITING XML DOC:");
> out.println(cdoc.xmlText(new XmlOptions().setSavePrettyPrint()));
> cdoc.save(new File("junk.xml"),
> new XmlOptions().setSavePrettyPrint());
>
> out.println();
> out.println("----------------- READING XML DOC:");
> String fname = "junk.xml";
> XmlOptions xopts = new XmlOptions()
> .setLoadLineNumbers()
> .setLoadStripWhitespace()
> .setDocumentSourceName(fname);
>
> cdoc = ConfigDocument.Factory.parse(fname, xopts); // <--EXCEPTION
> out.println("is-valid: " +cdoc.validate(xopts));
> }
> catch (IOException e) {
> e.printStackTrace();
> }
> catch (XmlException e) {
> e.printStackTrace();
> }
> }
> }
>
> PROGRAM RUN
> ---------------
> /usr/lib/jvm/java-6-sun/bin/java -cp
> target/test-classes/:target/test.jar:/usr/share/java/xmlbeans-2.5.0/lib/xbean.jar
> org.scrapbook.XbeanFun
>
> SCHEMA COMPILE
> ---------------
> /usr/share/java/xmlbeans-2.5.0/bin/scomp -debug -javasource 1.5 \
> -d ./target/gen-classes/test \
> -src ./src/main/gen-java/test \
> -out ./target/test.jar \
> src/main/resources/schemas/test.xsd \
> ./xmlbeans.xsdconfig
> Time to build schema type system: 0.966 seconds
> Time to generate code: 0.077 seconds
> Time to compile code: 1.446 seconds
> Compiled types to: ./target/test.jar
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
________
What if the Hokey Pokey IS what it's all about?
-- Anonymous
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]