users@jaxb.java.net

Re: Updating an XML FIle

From: Geoff Bawn <Geoff.Bawn_at_PPA.NHS.UK>
Date: Tue, 26 Aug 2003 14:10:49 +0100

Malachi

Thanks for replying.

I'll try to explain with an example. We have 3 systems all using the same schema file as follows:

<------Schema ¯-->

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified">
        <xsd:element name="Root">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="SystemA"/>
                                <xsd:element ref="SystemB" minOccurs="0"/>
                                <xsd:element ref="SystemC" minOccurs="0"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
        <xsd:element name="SystemA" type="xsd:string"/>
        <xsd:element name="SystemB" type="xsd:string"/>
        <xsd:element name="SystemC" type="xsd:string"/>
</xsd:schema>

<---- End Schema ¯---->

SystemA data is mandatory, SystemB and SystemC data is optional.

System A creates the original XML e.g.

<Root>
     <SystemA>data for system A here </SystemA>
</Root>

SystemB needs to unmarshal the XML, add their bit of data, and marshall the content to another XML file to be picked up by SystemC. The XML should look like this:

<Root>
     <SystemA>data for system A here </SystemA>
     <SystemB>data for system B here </SystemB>
</Root>

The problem is that if I unmarshal the original XML file created by SystemA, then I cannot just call the set methods to populate SystemB data as I get a null exception. One alternative is for SystemB and SystemC to regenerate the whole file using ObjectFactory - easy in this example but much more difficult in a real example.

Hope this makes sense.


Geoff Bawn
Phone (0191) 203-5864
E-Mail Geoff.Bawn_at_PPA.NHS.UK
Fax (0191) 203-5264


>>> malachi_at_eoti.org 13:42:20 26 August 2003 >>>
Perhaps I am missing something. You want optional tags, but you don't want to know whether they were provided?

IE, if your XML file looks like:
        <myRoot>
                <optionalTag/>
        </myRoot>

and another looks like:
        <myRoot/>

you don't want to know the difference?


Malachi


On Tue, 26 Aug 2003 08:15:12 +0100, Geoff Bawn <Geoff.Bawn_at_PPA.NHS.UK>
wrote:

> I am fairly new to JAXB and so I am wondering if anybody in the group can
> give me some advice on the best way to update an XML file using JAXB.
>
> In an application I am developing, the XML passes through a number of
> different systems with each system adding data to the original XML file.
> We have a common format (dtd/schema) for the XML file with each system's
> elements being defined as optional.
>
> I was hoping to simply unmarshal the file, do any updating on the content
> object using the set methods, then marshal back to a new version of the
> file.
>
> The problem I am having is that if the XML file does not contain an empty
> tag value for the optional element, then the JAXB set method returns a
> null exception. I can get round this by making the elements mandatory and
> have the original system generate empty element values for all systems,
> but this seems a bit messy.
>
> Another alternative is to create a new version of the file using
> ObjectFactory using the original values e.g.
> newRules.setFormNumber(oldRules.getFormNumber());
> and adding on the new values - but this seems a bit long winded.
>
> Am I missing anything? Can anybody suggest what is the best way to do
> this?
>
>
>
> Geoff Bawn
> Phone (0191) 203-5864
> E-Mail Geoff.Bawn_at_PPA.NHS.UK
> Fax (0191) 203-5264
>
>
> *** IMPORTANT NOTICE ***
> *** PPA DISCLAIMER ***
> This e-mail and any attachments transmitted with it, including replies
> and forwarded copies subsequently transmitted (which may contain
> alterations), contains information which may be confidential and which
> may also be privileged.
> The content of this e-mail is for the exclusive use of the intended
> recipient(s). If you are not the intended recipient(s), or the person
> authorised as responsible for delivery to the intended recipient(s),
> please note that any form of distribution, copying or use of this e-mail
> or the information in it is strictly prohibited and may be unlawful.
> If you have received this e-mail in error please notify the Network Team > at the Prescription Pricing Authority via e-mail to
> network.team_at_ppa.nhs.uk including a copy of this message. Please then
> delete this e-mail and destroy any copies of it.
> Further, we make every effort to keep our network free from viruses.
> However, you do need to validate this e-mail and any attachments to it
> for viruses, as we can take no responsibility for any computer virus that > might be transferred by way of this e-mail.
> This e-mail is from the Prescription Pricing Authority whose principal
> office is at Bridge House, 152 Pilgrim Street, Newcastle-upon-Tyne, NE1 > 6SN. Switchboard Telephone Number :-+44 (0)191 232 5371
>
>



-- 
 
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net 
For additional commands, e-mail: users-help_at_jaxb.dev.java.net 
***  IMPORTANT NOTICE ***
***     PPA DISCLAIMER    ***
This e-mail and any attachments transmitted with it, including replies and forwarded copies subsequently transmitted (which may contain alterations), contains information which may be confidential and which may also be privileged.
The content of this e-mail is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), or the person authorised as responsible for delivery to the intended recipient(s), please note that any form of distribution, copying or use of this e-mail
or the information in it is strictly prohibited and may be unlawful.
If you have received this e-mail in error please notify the Network Team at the Prescription Pricing Authority via e-mail to network.team_at_ppa.nhs.uk including a copy of this message. Please then delete this e-mail and destroy any copies of it.
Further, we make every effort to keep our network free from viruses. However, you do need to validate this e-mail and any attachments to it for viruses, as we can take no responsibility for any computer virus that might be transferred by way of this e-mail.
This e-mail is from the Prescription Pricing Authority whose principal office is at Bridge House, 152 Pilgrim Street, Newcastle-upon-Tyne, NE1 6SN. Switchboard Telephone Number :- +44 (0)191 232 5371
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net