// Read in the complete file into a byte[]
      File file = new File("c:/log4j.properties");
      FileInputStream fis = new FileInputStream(file);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      while(fis.available()>0) {
         baos.write(fis.read());
      }
      byte[] content = baos.toByteArray();

      // SignatureValueType is my Castor-generated Complex type
      // which has a child of type base64Binary
      SignatureValueType sig = new SignatureValueType();
      sig.setContent(content);

      // Debug output of XML data
      sig.marshal(new PrintWriter(System.out));



you will get this:


<?xml version="1.0" encoding="UTF-8"?>
<SignatureValueType xmlns="http://www.w3.org/2000/09/xmldsig#";>IyBEZWZhdWx0IHNldHRpbmdzOiBwcmludCBldmVyeXRoaW5nDQpsb2c0ai5yb290Q2F0ZWdvcnk9REVCVUcsIGRlc3QxDQpsb2c0ai5hcHBlbmRlci5kZXN0MT1vcmcuYXBhY2hlLmxvZzRqLkNvbnNvbGVBcHBlbmRlcg0KbG9nNGouYXBwZW5kZXIuZGVzdDEubGF5b3V0PW9yZy5hcGFjaGUubG9nNGouUGF0dGVybkxheW91dA0KbG9nNGouYXBwZW5kZXIuZGVzdDEubGF5b3V0LkNvbnZlcnNpb25QYXR0ZXJuPSVyIFsldF0gJS01cCAlYyAtICVtJW4NCg0KIyBQcmludCBvbmx5IG1lc3NhZ2VzIG9mIGxldmVsIFdBUk4gb3IgYWJvdmUgaW4gdGhlIHBhY2thZ2Ugb3JnLmFwYWNoZS4qDQpsb2c0ai5sb2dnZXIub3JnLmFwYWNoZT1XQVJODQpsb2c0ai5sb2dnZXIub3JnLmFwYWNoZS54bWw9REVCVUcNCmxvZzRqLmxvZ2dlci5vcmcuYXBhY2hlLmF4aXMuY29uZmlndXJhdGlvbj1ERUJVRw==</SignatureValueType>



Smith, Duane E (GE Consumer & Industrial) schrieb:
If using hexBinary how would I get the file contents into the castor create class.
I would need to define a binary array somehow,  and then stream the file 
somehow into the array,  correct?

Any code snippet would be great

Duane

-----Original Message-----
From: Mike Haller [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 08, 2005 10:46 AM
To: [email protected]
Subject: Re: [castor-user] Including binary file into XML


You can use "xsd:hexBinary" or "xsd:base64Binary"

http://www.w3.org/TR/xmlschema-2/#hexBinary
http://www.w3.org/TR/xmlschema-2/#base64Binary

And try to rename "File" to "FileContent" or something like that :-)
Also think about meta-information like last-modification date, filesystem attributes, if you need this.

Smith, Duane E (GE Consumer & Industrial) schrieb:

We have the need to embed a file into the XML.
Trying to figure out the best way to setup an xsd file to allow the source 
generator to create the class file.

XSD file would look similiar to the below
I found some mention in the docs a type that would use a byte array
But I don't know the process to read a file and load the byte array,  and 
reverse the process to go from the xml back to a file.

Thanks for any assistance

        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
        <xsd:element name="FileRequest" type="FileRequestType" />
            <xsd:complexType name="FileRequestType">
              <xsd:sequence>
                  <xsd:element name="Status"       type="xsd:string"     minOccurs="1" 
maxOccurs="1"/>
                  <xsd:element name="FileName" type="xsd:string"             minOccurs="1" 
maxOccurs="1"/>
                  <xsd:element name="File" type="????"             minOccurs="1" 
maxOccurs="1"/>
              </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>

Duane Smith
Information Technology
Appliance Engineering Systems Support
GE Consumer & Industrial
Phone (502) 452-7843   *334-7843
Fax  (502) 452-0512



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to