Hello,
I am not a real expert, but I think the file "content1.xml" (after your
modification) is not compliant with your schema definition (e.g. the first /
root element has to be a "page" element). So you cannot use an XMLBeans object
derived from your schema file in this case. Perhaps, if you know the final
structure of your modified document, you can create a corresponding schema,
generate the corr. XMLBeans and use that to do the parsing.
Regards,
Hans-Dieter Cordes
-----Original Message-----
From: Matthias Wessendorf [mailto:[EMAIL PROTECTED]
Sent: Mittwoch, 8. Juni 2005 17:10
To: [email protected]
Subject: problems on modifing XML files with XML_BEANS
Hi,
I am using XmlBeans for reading content of xml files. That works fine and all
works like I expected.
But when I try to write modified content to the specific xml file, something
goes wrong. I guess I am missing
something.
here are some steps of my process:
I have schema and I generate java files.
I have content inside a xml file (depends on that schema)
Reading with "Factory.parse(xmlfile)" is not a problem (if I DON'T change that
stuff)
here is my small schema:
--------------------------------------------------------
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo.com"
xmlns:pb="http://foo.com"
elementFormDefault="qualified">
<xs:element name="page">
<xs:complexType>
<xs:sequence>
<xs:element name="modification" type="xs:dateTime"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="header" type="xs:string" />
<xs:element name="container" type="pb:containerType"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute use="required" name="id" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:complexType name="containerType">
<xs:sequence>
<xs:element name="modification" type="xs:dateTime"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="contentblock" type="pb:contentBlockType"
maxOccurs="unbounded"/>
<xs:element name="container" type="pb:containerType"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute use="required" name="id" type="xs:string" />
</xs:complexType>
<xs:complexType name="contentBlockType">
<xs:sequence>
<xs:element name="modification" type="xs:dateTime"/>
<xs:element name="text" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="headline" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute use="required" name="id" type="xs:string" />
</xs:complexType>
</xs:schema>
--------------------------------------------------------
and here is a very small XML file (based upon schema):
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://FOO.com" id="content1">
<type>press</type>
<header>HEADER</header>
<modification>2005-04-27T09:30:10</modification>
<container id="container1">
<type>textcontainer</type>
<modification>2005-04-19T09:30:10</modification>
<contentblock id="contentblock1">
<type>textcontent</type>
<text>fooooooo bar BAR FOO</text>
<modification>2005-05-30T09:30:10</modification>
</contentblock>
</container>
</page
--------------------------------------------------------
No I modify the stuff and after that I do:
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
page.save(xmlFile, xmlOptions);
When I now read a second time my xml (the modified stuff) I got this message:
org.apache.xmlbeans.XmlException: C:\content1.xml:0: error: The document is not
a [EMAIL PROTECTED]://foo.com: multiple document elements
I guess this is because of my (re-written) xml file has no root element <page>
my content1.xml looks now like:
<?xml version="1.0" encoding="UTF-8"?>
<xml-fragment id="content1">
<foo:type xmlns:foo="http://foo.com">press</foo:type>
<foo:header xmlns:foo="http://foo.com">hallo1</foo:header>
<foo:modification
xmlns:foo="http://foo.com">2005-06-08T16:57:23.672+02:00</foo:modification>
<foo:container id="container1" xmlns:foo="http://foo.com">
<foo:type>textcontainer</foo:type>
<foo:modification>2005-04-19T09:30:10</foo:modification>
<foo:contentblock id="contentblock1">
<foo:type>textcontent</foo:type>
<foo:text>hallo3</foo:text>
<foo:modification>2005-06-08T16:57:23.672+02:00</foo:modification>
<foo:headline>hallo2</foo:headline>
</foo:contentblock>
</foo:container>
</xml-fragment>
What am I doing wrong on using XmlBeans to *change* XML files?
Thanks for any advice.
-Matthias
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]