DateFormat parse validation

This didn't seem to show up first time so I'll try again.
The docs and tutorials indicate that DateFormat.parse should thorw an error if an invalid date is provided. However, the following throws no error:
SimpleDateFormat formatter_mmddyy = new SimpleDateFormat ("MM/dd/yy");
Date theDate = formatter_mmddyy.parse("13/22/05");
What is the correct way to validate dates?
-- Frank

Depending on how strict you want your validation to be you can either:
a) leave it as is and let it adjust as it sees fit (rolling forward if you try something like you just did)
b) Call setLenient(false) to make it not do that, but allow extraneous cahracters at the end (so Strings like "12/22/05yasureyoubetcha" still come out valid)
c) use the version of parse that takes a ParsePosition and manually verify that the passed in ParsePosition does not indicate an error and shows that the whole String was consumed during parsing.
That's my take on it anyway
Good Luck
Lee

Similar Messages

  • DateFormat.parse() reads 12:00:00 as 00:00:00?

    Hi, i have a method, which uses DateFormat.parse() function, and i want to check whether a date and time input is valid. as you can see from the following code; i have defined the format as (dd-mm-yyyy at hh:mm:ss). the problem is, if i pass a string as (dd-mm-yyyy at 12:21:23), the method changes hour field to '00'. i.e., the line denoted as LINE N in the code prints out 'dd-mm-yyyy at 00:21:23'. i have tested other hours and they are all fine, 00 is interpreted as 00, 24 is 00 which is fine, but 12 is also parsed to 00.... any way to change this please?
    Many thanks!
    public boolean isValidDate(String dt)
            boolean isValid=false;
            DateFormat datef=new SimpleDateFormat("dd-MM-yyyy 'at' hh:mm:ss",Locale.UK);
            java.util.Date d = new java.util.Date();
            try{
                d=datef.parse(dt);
                //////////////////////  LINE N //////////////////////////////////////////
                System.out.println("is this right"+d.toString());
                /////////////////////  LINE N //////////////////////////////////////////
                int hr = d.getHours();
                System.out.println("This is the hour "+hr);
                if(hr<=18&&hr>=9)
                    isValid=true;
                    System.out.println("hour ok");
                else{System.out.println("hour not ok");}
            catch(ParseException pe)
                isValid=false;
            return isValid;       
        }

    use gregoriancalendar instead
    -->
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Greg
    orianCalendar.htmlTrue.
    @OP. You should never call getHours() on a date object, you should always use a Calendar.
    Kaj

  • Is is possible to allow multiple date format strings pass DateFormat.parse?

    I'm trying to use DateFormat.parse to validate a date in the 20/12/08 format. I would like to allow users to input 20-12-08 or 20 12 08.
    The code currently looks like this:
    formatter = DateFormat.getDateInstance(DateFormat.SMALL, US);It is currently throwing an exception if 10-12-08 is sent in where as 10/12/08 works just fine.
    Is there a alternate us locale that is more lenient?
    setLenient(true) didn't solve the problem for me. I think that would accept 32/12/08 not 10-12-08.
    I could parse the date string and replace - or ' ' with a /.. Is that best practice?
    What other options do I have? Could I use SimpleDateFormat somehow?
    Thanks for the input

    That just doesn't seem clean. It will work, but I would rather not have a valid application flow use an exception to get its job done.
    The application is also international, so many locales on one format is valid. The US user base seems to think they can type in the date however they want. So passed into the method is the locale, I would have to modify a lot of code to send in a list of valid locales.
    The best solution for me would be to have a locale that would allow - or ' ' or /. That way I still only have to make one call to df.parse and an exception produces an invalid date message. Is that possible?
    Thanks

  • DateFormat parsing problem

    Hi,
    A little limitation I have discovered in DateFormat.
    I'm using SimpleDateFormat, and I supply the format "HH:mm"
    I expect the DateFormat parsing to fail when calling parse() for Strings such as "12:13:13", since in the format there is no seconds-resolution.
    Instead, the parsing runs without exception and returns the time 12:13:00 (The seconds are truncated).
    Is thyere a way to make the DateFormat to fail and throw an exception in such a scenario?
    Thanks,
    Miki

    I doubt it. Also, if you enter an invalid date such as Dec 34 2004, it may (or may not) return an invalid date such as something like Aug 23 1834 rather than throw an exception. I think its best to pass the string to a validate format class that you custom write to check the format (such as xx:xx:xx), and also a validate date class (after passing the validate format) that you custom write to see if its a valid date (such as Dec 34, or if Feb 29, 2003 really is a leap year).
    Actually, I dont even use the classes such as DateFormat class directly in my code. Instead, I have a custom class with a host of static functions (containing DateFormat) to do all kinds of date/timestamp/string convertions to deal with dates. My code uses that class instead.

  • DateFormat.parse

    Hi all,
    I am trying to parse some Strings into date objects, but i'm getting some strange output.
    The dates (Strings) that go into my program are:
    2005/3/08 09:12:38
    2005/3/10 17:29:57
    2005/3/11 15:39:59
    2005/3/23 13:30:03
    2005/3/23 13:32:49
    my code should take these strings, parse them into dates, add them to a List and sort the list. But the output i get is:
    Mon Aug 26 09:12:00 BST 2013
    Wed Aug 26 17:29:00 BST 2015
    Thu Aug 25 15:39:00 BST 2016
    Fri Aug 25 13:30:00 BST 2028
    Fri Aug 25 13:32:00 BST 2028
    as u can see - these are not the strings i entered originally. the code i am using is:
    public java.util.Date dateConverter(String dateString) throws Exception
    {     int intMonth = 99;
         String [] months = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
              String month = dateString.substring(4,7);
         for (int i = 0 ; i < 12 ; i++)
         {     if (months[i].equals(month))
              {     intMonth = i+1;
         dateString = dateString.substring(24,28) + "/" + intMonth + "/" + dateString.substring(8,10) + " " + dateString.substring(10,20);
         java.util.Date newDate = dateFormat.parse(dateString);
         return newDate;
    can anyone tell me whats missing from my code, and how i can get the correct output.
    thanks

    What happens if you do this? dateString = dateString.substring(24,28) + "/" + intMonth + "/" + dateString.substring(8,10) + " " + dateString.substring(10,20);
    java.util.Date newDate =dateFormat.parse(dateString);
    System.out.println("Parsing string " + dateString + " into date " + newDate);

  • DateFormat parse method usage

    Hi all,
    I am using the following code to parse the date String object to Date Object -
    ======================================================================
    if(dateString == null || dateString.trim().equals(""))
    return null;
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT,
    Locale.getDefault());
    Date d = null;
    try
    dateFormatter.setLenient(false);
    d = dateFormatter.parse(dateString);
    catch(ParseException pe)
    e.printStackTrace();
    =================================================================
    This code works perfectly for all formats of String objects I give except for the format - "12/12/12/1" in which case it converts to following date object -
    "Wed Dec 12 00:00:00 IST 2012" although its an invalid date String.
    Please let me know how I could have correct validation done in such cases or if this is the right behavior for DateFormat class.
    Thanks in advance!!

    I'm not going to comment on how exactly the parse method does its business, but I can suggest you use a regex pattern to validate the input you will send the parse method.
    Here is some info from the CodeProject website on date validation(Note that this is aimed at .NET - but regex works the same in Java as it does in .NET [i think]):
    Dates: As with numbers, we need two validators: a key-press validator, and a completion validator. The key-press validator can be pretty simple, if we limit how our user enters the date. Let’s say that we want to validate for the U.S. date format mm/dd/yyyy. Here is a validator that will do that:
    ^([0-9]|/)*$
    The regex reads: “Match any string that contains a sequence of zero or more characters, where each character is either a digit or a slash.” This validator will give the user immediate feedback if they enter an invalid character, such as an ‘a’.
    Copy that regex to Regex Tester and give it a try. Note that the validation fails if the user enters dashes, instead of slashes, between the parts of the date. How could we increase the flexibility of our regex to accommodate dashes? Think about the question for a minute before moving on.
    All we need to do is add a dash to the alternates group:
    ^([0-9]|/|-)*$
    We could add other alternates to make the regex as flexible as it needs to be.
    The completion validator does a final check to determine whether the input matches a complete date pattern:
    ^[0-2]?[1-9](/|-)[0-3]?[0-9](/|-)[1-2][0-9][0-9][0-9]$
    The regex reads as follows: "Match any string that conforms to this pattern: The first character can be a 0, 1, or 2, and it may be omitted. The second character can be any number and is required. The next character can be a slash or a dash, and is required…” And so on. This regex differs from the ones we used before in that it specifies each character of the pattern—the pattern is more of a template than a formula.
    Note the first character of the regex: ‘[0-2]’. This character points out that we can limit allowable digits to less than the full set. We can also expand them; for example, ‘[0-9A-F]’ would allow any hexadecimal digit. In fact, we can use this structure, known as a character class, to specify any set of characters we want. For example, the character class ‘[A-Z]’ allows capital letters, and ‘[A-Za-z]’ allows upper or lower-case letters.
    Our date regex also points out some of the limitations of regex validation. Paste the date regex shown into Regex Tester and try out some dates. The regex does a pretty good job with run-of-the-mill dates, but it allows some patently invalid ones, such as ‘29/29/2006’, or ‘12/39/2006'. The regex is clearly not ‘bulletproof’.
    We could beef up the regular expression with additional features to catch these invalid dates, but it may be simpler to simply use a bit of .NET in the completion validator:
    bool isValid = DateTime.TryParse(dateString, out dummy);
    We gain the additional benefit that .NET will check the date for leap year validity, and so on. As always, the choice comes down to: What is simpler? What is faster? What is more easily understood? In my shop, we use a regex for the key-press validator, and DateTime.TryParse() for the completion validator.
    Oh - and there is another regex validator:
    ^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$
    which matches the yyyy-mm-dd date format and also validates month and number of days in a month. Could be improved as currently all leap year dates (yyyy-02-29) will validate.
    Sorry if I couldn't be of more help...
    Edited by: JoKiLlSyA on Oct 9, 2008 11:22 PM

  • ORA-31011 : Weird case of parsing/validation failure...

    Hello all,
    It seems that when trying to insert into an XMLTYPE schema-bound column I am hitting a validation error that I cannot replicate with either XMLSpy os Stylus Studio.
    Here follow the schemas that are used, and the offending XML :
    envelope-consult.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace" targetNamespace="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="EORI-CONSULT-ENVELOPE-1.0">
         <xs:annotation>
              <xs:documentation>
                   This XML schema can be used by a national application to
                   validate consultation envelopes sent to the EORI
                   CDCO application. It can also be used to validate
                   consultation responses and acknowledgement envelopes
                   sent back by the EORI CDCO application. The number of
                   transactions in an envelope is 5.
                   For a request envelope, each transaction
                   contains a single app.message.
                   For a response envelope, each transaction contains
                   a single status element and a single app.message
                   element.
              </xs:documentation>
         </xs:annotation>
      <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
         <xs:element name="envelope">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="header" type="Header" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="transaction" type="Transaction" maxOccurs="5"/>
                   </xs:sequence>
                   <xs:attribute name="id" type="xs:string" use="required"/>
                   <xs:attribute ref="xml:lang" default="en-GB"/>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="AppMessage">
              <xs:sequence>
                   <xs:element ref="abstract.message"/>
              </xs:sequence>
              <xs:attribute name="id" type="xs:string" use="required"/>
         </xs:complexType>
         <xs:complexType name="Binary">
              <xs:simpleContent>
                   <xs:extension base="xs:base64Binary">
                        <xs:attribute name="mime.type" type="xs:string" default="application/octet-stream"/>
                   </xs:extension>
              </xs:simpleContent>
         </xs:complexType>
         <xs:complexType name="BusinessRef">
              <xs:sequence>
                   <xs:element ref="abstract.ref"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="Header">
              <xs:attribute name="name" type="xs:string" use="required"/>
              <xs:attribute name="value" type="xs:string" use="required"/>
         </xs:complexType>
         <xs:complexType name="MMIMessageType">
              <xs:simpleContent>
                   <xs:extension base="xs:string">
                        <xs:attribute ref="xml:lang" default="en-GB"/>
                   </xs:extension>
              </xs:simpleContent>
         </xs:complexType>
         <xs:complexType name="Status">
              <xs:sequence>
                   <xs:element name="mmi.message" type="MMIMessageType" minOccurs="0"/>
                   <xs:element name="status.detail" type="StatusDetail" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
              <xs:attribute name="category" type="StatusCategory" use="required"/>
              <xs:attribute name="location" type="xs:string" use="required"/>
         </xs:complexType>
         <xs:simpleType name="StatusCategory">
              <xs:restriction base="xs:string">
                   <xs:enumeration value="ok"/>
                   <xs:enumeration value="error"/>
                   <xs:enumeration value="rejected"/>
                   <xs:enumeration value="warning"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:complexType name="StatusDetail">
              <xs:sequence>
                   <xs:element name="business.ref" type="BusinessRef" minOccurs="0"/>
                   <xs:element name="binary" type="Binary" minOccurs="0"/>
                   <xs:element name="mmi.message" type="MMIMessageType" minOccurs="0"/>
              </xs:sequence>
              <xs:attribute name="category" type="StatusDetailCategory" use="required"/>
              <xs:attribute name="location" type="xs:string" use="required"/>
              <xs:attribute name="code" type="xs:NMTOKEN" use="required"/>
         </xs:complexType>
         <xs:simpleType name="StatusDetailCategory">
              <xs:restriction base="xs:string">
                   <xs:enumeration value="error"/>
                   <xs:enumeration value="info"/>
                   <xs:enumeration value="warning"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:complexType name="Transaction">
              <xs:sequence>
                   <xs:element name="header" type="Header" minOccurs="0" maxOccurs="unbounded"/>
                   <xs:element name="status" type="Status" minOccurs="0"/>
                   <xs:element name="app.message" type="AppMessage"/>
              </xs:sequence>
              <xs:attribute name="id" type="xs:string" use="required"/>
         </xs:complexType>
         <xs:element name="abstract.message" abstract="true"/>
         <xs:element name="abstract.ref" abstract="true"/>
    </xs:schema>EORI-consult.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:envelope="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" xmlns="urn:publicid:-:DGTAXUD:EORI:CONSULT:1.0" targetNamespace="urn:publicid:-:DGTAXUD:EORI:CONSULT:1.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
         <xs:annotation>
              <xs:documentation>
                   This XML schema contains the definitions of data
                   elements and messages specific to the EORI consult
                   functionality.
              </xs:documentation>
         </xs:annotation>
         <xs:import namespace="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" schemaLocation="envelope-consult.xsd"/>
         <xs:include schemaLocation="EORI-data.xsd"/>
         <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
         <!-- Base types -->
      <xs:simpleType name="Date">
              <xs:annotation>
                   <xs:documentation>Date format</xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:pattern value="\d{4}\d{2}\d{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:complexType name="EoriRecord">
              <xs:sequence>
                   <xs:element name="eori.record.ref" type="EoriNumberRef"/>
                   <xs:element name="tc.number.list" type="TcNumberList"/>
                   <xs:element name="economic.operator.details" type="EconomicOperatorDetails"/>
                   <xs:element name="legal.status.list" type="LegalStatusPeriodList"/>
                   <xs:element name="establishment.address.list" type="EstablishmentAddressPeriodList"/>
                   <xs:element name="vat.list" type="VatList"/>
                   <xs:element name="contact.list" type="ContactPeriodList"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="EconomicOperatorDetails">
              <xs:sequence>
                   <xs:element name="full.name" type="EOFullName"/>
                   <xs:element name="short.name" type="EOShortName"/>
                   <xs:element name="establishment.date" type="Date" minOccurs="0"/>
                   <xs:element name="person.type.code" type="TypePerson" minOccurs="0"/>
                   <xs:element name="economic.activity.code" type="ActivityCode" minOccurs="0"/>
                   <xs:element name="start.date" type="Date"/>
                   <xs:element name="expiry.date" type="Date" minOccurs="0"/>
                   <xs:element name="publication.ind" type="xs:boolean" minOccurs="0"/>
              </xs:sequence>
         </xs:complexType>     
      <xs:complexType name="ValidityPeriod">
              <xs:sequence>
                   <xs:element name="start.date" type="Date"/>
                   <xs:element name="end.date" type="Date" minOccurs="0"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="ContactPeriod">
              <xs:sequence>
                   <xs:element name="contact" type="Contact"/>
                   <xs:element name="validity.period" type="ValidityPeriod"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="ContactPeriodList">
              <xs:sequence>
                   <xs:element name="contact" type="ContactPeriod" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>          
         </xs:complexType>
         <xs:complexType name="EstablishmentAddressPeriod">
              <xs:sequence>
                   <xs:element name="establishment.address" type="EstablishmentAddress"/>
                   <xs:element name="validity.period" type="ValidityPeriod"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="EstablishmentAddressPeriodList">
              <xs:sequence>
                   <xs:element name="establishment.address" type="EstablishmentAddressPeriod" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="LegalStatusPeriod">
              <xs:sequence>
                   <xs:element name="legal.status" type="LegalStatus"/>
                   <xs:element name="validity.period" type="ValidityPeriod"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="LegalStatusPeriodList">
              <xs:sequence>
                   <xs:element name="legal.status" type="LegalStatusPeriod" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="EoriRecordFull">
              <xs:complexContent>
                   <xs:extension base="EoriRecord">
                        <xs:sequence>
                             <xs:element name="aeo.certificate.lifecycle.list" type="AeoCertificateLifecycleList" minOccurs="0"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="AeoCertificateLifecycleList">
              <xs:sequence>
                   <xs:element name="aeo.certificate.lifecycle" type="AeoCertificateLifecycle" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="AeoCertificateLifecycle">
              <xs:sequence>
                   <xs:element name="start.date" type="Date"/>
                   <xs:element name="end.date" type="Date" minOccurs="0"/>
                   <xs:element name="aeo.certificate.ref" type="AeoCertificateNumber" minOccurs="0"/>
              </xs:sequence>
         </xs:complexType>          
         <!-- Consultation messages -->
         <xs:element name="eori.record.snapshot.consultation.request" substitutionGroup="envelope:abstract.message">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="snapshot.request.list" type="EoriRecordSnapshotRequestList"/>
                   </xs:sequence>
                <xs:attribute ref="xml:lang" default="en-GB"/>                              
              </xs:complexType>
         </xs:element>
         <xs:element name="eori.record.full.consultation.request" substitutionGroup="envelope:abstract.message">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="full.request.list" type="EoriRecordFullRequestList"/>
                   </xs:sequence>
                   <xs:attribute ref="xml:lang" default="en-GB"/>               
              </xs:complexType>
         </xs:element>
         <xs:element name="eori.record.snapshot.consultation.response" substitutionGroup="envelope:abstract.message">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="snapshot.response.list" type="EoriRecordSnapshotResponseList"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="eori.record.full.consultation.response" substitutionGroup="envelope:abstract.message">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="full.response.list" type="EoriRecordFullResponseList"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Acknowledgement business references -->
         <xs:element name="full.request" type="EoriRecordFullRequest" substitutionGroup="envelope:abstract.ref"/>
         <xs:element name="snapshot.request" type="EoriRecordSnapshotRequest" substitutionGroup="envelope:abstract.ref"/>
         <!-- Snapshot: Consultation messages -->
         <xs:complexType name="SnapshotConsultationRequest">
              <xs:sequence>
                   <xs:element name="snapshot.request.list" type="EoriRecordSnapshotRequestList"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="SnapshotConsultationResponse">
              <xs:sequence>
                   <xs:element name="snapshot.response.list" type="EoriRecordSnapshotResponseList"/>
              </xs:sequence>
         </xs:complexType>
         <!-- Full: Consultation messages -->
         <xs:complexType name="FullConsultationRequest">
              <xs:sequence>
                   <xs:element name="full.request.list" type="EoriRecordFullRequestList"/>                              
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="FullConsultationResponse">
              <xs:sequence>
                   <xs:element name="full.response.list" type="EoriRecordFullResponseList"/>
              </xs:sequence>
         </xs:complexType>
         <!-- Snapshot: Message structures -->
         <xs:complexType name="EoriRecordSnapshot">
              <xs:sequence>
                   <xs:element name="eori.record.ref" type="EoriNumberRef"/>
                   <xs:element name="tc.number.list" type="TcNumberList" minOccurs="0"/>
                   <xs:element name="economic.operator.details" type="EconomicOperatorDetails"/>
                   <xs:element name="legal.status" type="LegalStatus" minOccurs="0"/>
                   <xs:element name="establishment.address" type="EstablishmentAddress"/>
                   <xs:element name="vat.list" type="VatList" minOccurs="0"/>
                   <xs:element name="contact" type="Contact" minOccurs="0"/>
                   <xs:element name="aeo.certificate.ref" type="AeoCertificateNumber" minOccurs="0"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordSnapshotRequestList">
              <xs:sequence>
                   <xs:element name="snapshot.request" type="EoriRecordSnapshotRequest" maxOccurs="20"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordSnapshotRequest">
              <xs:sequence>
                   <xs:element name="eori.record.ref" type="EoriNumberRef"/>
                   <xs:element name="applicable.date" type="Date"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordFullRequestList">
              <xs:sequence>
                   <xs:element name="full.request" type="EoriRecordFullRequest" maxOccurs="20"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordFullRequest">
              <xs:sequence>
                   <xs:element name="eori.record.ref" type="EoriNumberRef"/>
                   <xs:element name="consultation.purpose.code" type="ConsultationPurpose" minOccurs="0"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordSnapshotResponseList">
              <xs:sequence>
                   <xs:element name="snapshot.response" type="EoriRecordSnapshotResponse" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordSnapshotResponse">
              <xs:sequence>
                   <xs:element name="eori.record.snapshot" type="EoriRecordSnapshot"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordFullResponseList">
              <xs:sequence>
                   <xs:element name="full.response" type="EoriRecordFullResponse" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EoriRecordFullResponse">
              <xs:sequence>
                   <xs:element name="eori.record.full" type="EoriRecordFull"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>EORI-data.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
         <xs:annotation>
              <xs:documentation>
                   This XML schema contains the definitions of data
                   elements common to the messages exchanged in the
                   EORI download, upload and consultation
                   functionalities.
              </xs:documentation>
         </xs:annotation>
         <!-- List types -->
         <xs:complexType name="CountryList">
              <xs:sequence>
                   <xs:element name="country" type="Country" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="LegalStatusList">
              <xs:sequence>
                   <xs:element name="legal.status" type="LegalStatus" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="TcNumberList">
              <xs:sequence>
                   <xs:element name="tc.number" type="TcNumberRef" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="VatList">
              <xs:sequence>
                   <xs:element name="vat" type="Vat" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="CertificateInfoList">
              <xs:sequence>
                   <xs:element name="certificate.info" type="CertificateInfo" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>          
         </xs:complexType>     
         <xs:complexType name="ApplicationInfoList">
              <xs:sequence>
                   <xs:element name="application.info" type="ApplicationInfo" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>          
         </xs:complexType>     
         <!-- Complex types -->
         <xs:complexType name="CertificateInfo">
              <xs:sequence>
                   <xs:element name="aeo.certificate.ref" type="AeoCertificateNumber"/>
              </xs:sequence>          
         </xs:complexType>     
         <xs:complexType name="ApplicationInfo">
              <xs:sequence>
                   <xs:element name="aeo.application.ref" type="AeoApplicationNumber"/>
              </xs:sequence>          
         </xs:complexType>     
         <xs:complexType name="AeoCertificateNumber">
              <xs:sequence>
                   <xs:element name="country.code" type="CountryCode"/>
                   <xs:element name="aeo.certificate.type.code" type="AeoCertificateTypeCode"/>
                   <xs:element name="national.number" type="NationalAuthorisationNumber"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="AeoApplicationNumber">
        <xs:sequence>
          <xs:element name="country.code" type="CountryCode"/>
          <xs:element name="national.number" type="ApplicationNumber"/>
        </xs:sequence>
      </xs:complexType>
         <xs:complexType name="Contact">
              <xs:sequence>
                   <xs:element name="phone" type="PhoneNumber" minOccurs="0"/>
                   <xs:element name="fax" type="PhoneNumber" minOccurs="0"/>
                   <xs:element name="email" type="Email" minOccurs="0"/>
                   <xs:element name="name.address" type="NameAddress"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="Country">
              <xs:choice>
                   <xs:element name="country.code" type="CountryCode"/>
                   <xs:element name="country.name" type="CountryName"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="EoriNumberRef">
              <xs:sequence>
                   <xs:element name="country.code" type="CountryCode"/>
                   <xs:element name="national.number" type="EoNationalNumber"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="TcNumberRef">
              <xs:sequence>
                   <xs:element name="country" type="Country"/>
                   <xs:element name="national.number" type="TcNationalNumber"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EstablishmentAddress">
              <xs:sequence>
                   <xs:element name="language.code" type="LanguageCode"/>
                   <xs:element name="name" type="Name" minOccurs="0"/>
                   <xs:element name="street" type="Street"/>
                   <xs:element name="postcode" type="Postcode" minOccurs="0"/>
                   <xs:element name="city" type="City"/>
                   <xs:element name="country" type="Country"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="LegalStatus">
              <xs:sequence>
                   <xs:element name="language.code" type="LanguageCode"/>
                   <xs:element name="legal.status.description" type="LegalStatusDescription"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="NameAddress">
              <xs:sequence>
                   <xs:element name="language.code" type="LanguageCode"/>
                   <xs:element name="full.name" type="FullName"/>
                   <xs:element name="short.name" type="Name" minOccurs="0"/>
                   <xs:element name="street" type="Street"/>
                   <xs:element name="postcode" type="Postcode" minOccurs="0"/>
                   <xs:element name="city" type="City"/>
                   <xs:element name="country" type="Country"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="Vat">
              <xs:sequence>
                   <xs:element name="country.code" type="CountryCode"/>
                   <xs:element name="number" type="VATNationalNumber"/>
              </xs:sequence>
         </xs:complexType>
         <!-- Simple types -->
         <xs:simpleType name="Accepted">
              <xs:restriction base="xs:int">
                   <xs:pattern value="0|1"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="ActivityCode">
              <xs:restriction base="SingleLineString">
          <xs:length value="4"/>
          <xs:pattern value="[0-9]+"/>   
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="NationalAuthorisationNumber">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="29"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="AeoCertificateTypeCode">
              <xs:restriction base="SingleLineString">
                   <xs:length value="4"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="ApplicationNumber">
             <xs:restriction base="SingleLineString">
               <xs:minLength value="1"/>
               <xs:maxLength value="29"/>
             </xs:restriction>
           </xs:simpleType>
         <xs:simpleType name="City">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="35"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="ConsultationPurpose">
              <xs:restriction base="xs:string">
                   <xs:length value="1"/>
                   <xs:enumeration value="C"/>
                   <xs:enumeration value="Q"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="CountryCode">
              <xs:annotation>
                   <xs:documentation>
                        Country code format
                   </xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:pattern value="[A-Z][A-Z]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="CountryName">
              <xs:annotation>
                   <xs:documentation>Country name</xs:documentation>
              </xs:annotation>
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="30"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="Email">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="70"/>
                   <xs:pattern value="\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="EoNationalNumber">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="15"/>
                   <xs:pattern value="\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="TcNationalNumber">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="15"/>
                   <xs:pattern value="\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="LanguageCode">
              <xs:annotation>
                   <xs:documentation>
                        Language code format
                   </xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:pattern value="[a-z][a-z]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="LegalStatusDescription">
              <xs:annotation>
                   <xs:documentation>
                        Legal status value
                   </xs:documentation>
              </xs:annotation>
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="50"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="EOFullName">
              <xs:restriction base="xs:string">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="300"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="EOShortName">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="35"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="PhoneNumber">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="2"/>
                   <xs:maxLength value="35"/>
                   <xs:pattern value="\+\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="Postcode">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="9"/>
                   <xs:pattern value="\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="SingleLineString">
              <xs:annotation>
                   <xs:documentation>
                        Single line string: Avoid presence of \n (new
                        line) and \r (return) characters in the string.
                        Note that pattern ".*" is equivalent.
                   </xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:pattern value="[^\n\r]*"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="FullName">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="100"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="Name">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="35"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="Street">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="35"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="TypePerson">
              <xs:annotation>
                   <xs:documentation>
                        Type of person values as follows: 1-Natural
                        person, 2-Legal person and 3-Association of
                        persons. Values can be updated and retrieved by the CS/RD.
                   </xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:unsignedInt">
                   <xs:totalDigits value="1"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="VATNationalNumber">
              <xs:restriction base="SingleLineString">
                   <xs:minLength value="1"/>
                   <xs:maxLength value="15"/>
                   <xs:pattern value="\p{IsBasicLatin}+"/>
              </xs:restriction>
         </xs:simpleType>
    </xs:schema>xml.xsd
    <?xml version='1.0'?>
    <xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
    <xs:attribute name="lang" type="xs:language"/>
    <xs:attribute name="space" default="preserve">
      <xs:simpleType>
       <xs:restriction base="xs:NCName">
        <xs:enumeration value="default"/>
        <xs:enumeration value="preserve"/>
       </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="base" type="xs:anyURI"/>
    <xs:attributeGroup name="specialAttrs">
      <xs:attribute ref="xml:base"/>
      <xs:attribute ref="xml:lang"/>
      <xs:attribute ref="xml:space"/>
    </xs:attributeGroup>
    </xs:schema>(second part follows...)

    (continuing from above post ...)
    TestXML.xml
    <?xml version="1.0" encoding="utf-8"?>
    <env:envelope id="5555" xmlns="urn:publicid:-:DGTAXUD:EORI:CONSULT:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <env:header name="Version" value="1.0"/>
      <env:header name="From" value="EOS-CDCO"/>
      <env:header name="Originator" value="BE-EORI"/>
      <env:header name="InReplyTo" value="5554"/>
      <env:transaction id="1">
        <env:header name="InReplyTo" value="1"/>
        <env:status category="ok" location="/envelope[@id=&apos;5554&apos;]/transaction[@id=&apos;1&apos;]">
          <env:status.detail category="info" code="100" location="/envelope[@id=&apos;5554&apos;]/transaction[@id=&apos;1&apos;]/app.message[@id=&apos;1&apos;]">
            <env:business.ref>
              <full.request>
                <eori.record.ref>
                  <country.code>BE</country.code>
                  <national.number>123</national.number>
                </eori.record.ref>
                <consultation.purpose.code>C</consultation.purpose.code>
              </full.request>
            </env:business.ref>
            <env:mmi.message>Ok</env:mmi.message>
          </env:status.detail>
        </env:status>
        <env:app.message id="1">
          <eori.record.full.consultation.response>
            <full.response.list>
              <full.response>
                <eori.record.full>
                  <eori.record.ref>
                    <country.code>FR</country.code>
                    <national.number>123</national.number>
                  </eori.record.ref>
                  <tc.number.list>
                    <tc.number>
                      <country>
                        <country.code>AA</country.code>
                      </country>
                      <national.number>465466</national.number>
                    </tc.number>
                  </tc.number.list>
                  <economic.operator.details>
                    <full.name>a</full.name>
                    <short.name>a</short.name>
                    <establishment.date>19670813</establishment.date>
                    <person.type.code>1</person.type.code>
                    <economic.activity.code>1234</economic.activity.code>
                    <start.date>19670813</start.date>
                    <expiry.date>19670813</expiry.date>
                    <publication.ind>0</publication.ind>
                  </economic.operator.details>
                  <legal.status.list>
                    <legal.status>
                      <legal.status>
                        <language.code>aa</language.code>
                        <legal.status.description>status</legal.status.description>
                      </legal.status>
                      <validity.period>
                        <start.date>19670813</start.date>
                        <end.date>19670813</end.date>
                      </validity.period>
                    </legal.status>
                  </legal.status.list>
                  <establishment.address.list>
                    <establishment.address>
                      <establishment.address>
                        <language.code>aa</language.code>
                        <name>a</name>
                        <street>s</street>
                        <postcode>p</postcode>
                        <city>c</city>
                        <country>
                          <country.code>AA</country.code>
                        </country>
                      </establishment.address>
                      <validity.period>
                        <start.date>19670813</start.date>
                        <end.date>19670813</end.date>
                      </validity.period>
                    </establishment.address>
                  </establishment.address.list>
                  <vat.list>
                    <vat>
                      <country.code>AA</country.code>
                      <number>74455</number>
                    </vat>
                  </vat.list>
                  <contact.list>
                    <contact>
                      <contact>
                        <phone>+ 123</phone>
                        <fax>+ 123</fax>
                        <name.address>
                          <language.code>aa</language.code>
                          <full.name>a</full.name>
                          <short.name>a</short.name>
                          <street>s</street>
                          <postcode>p</postcode>
                          <city>c</city>
                          <country>
                            <country.code>AA</country.code>
                          </country>
                        </name.address>
                      </contact>
                      <validity.period>
                        <start.date>19670813</start.date>
                        <end.date>19670813</end.date>
                      </validity.period>
                    </contact>
                  </contact.list>
                  <aeo.certificate.lifecycle.list>
                    <aeo.certificate.lifecycle>
                      <start.date>19670813</start.date>
                      <end.date>19670813</end.date>
                    </aeo.certificate.lifecycle>
                  </aeo.certificate.lifecycle.list>
                </eori.record.full>
              </full.response>
            </full.response.list>
          </eori.record.full.consultation.response>
        </env:app.message>
      </env:transaction>
    </env:envelope>Here is the script that created the table and registered the schemas
    BEGIN     
       DBMS_XMLSCHEMA.REGISTERSCHEMA(
         SCHEMAURL => 'envelope-consult.xsd',
         SCHEMADOC => XDBURITYPE('/public/xsdfiles/EORI/envelope-consult.xsd').getBlob(),
         LOCAL     => TRUE,
         GENTYPES  => FALSE,
         GENBEAN   => FALSE,
         GENTABLES => FALSE,
         FORCE     => FALSE,
         CSID      => NLS_CHARSET_ID('AL32UTF8'),
         OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML);
    END;
    BEGIN     
       DBMS_XMLSCHEMA.REGISTERSCHEMA(
         SCHEMAURL => 'EORI-consult.xsd',
         SCHEMADOC => XDBURITYPE('/public/xsdfiles/EORI/EORI-consult.xsd').getBlob(),
         LOCAL     => TRUE,
         GENTYPES  => FALSE,
         GENBEAN   => FALSE,
         GENTABLES => FALSE,
         FORCE     => FALSE,
         CSID      => NLS_CHARSET_ID('AL32UTF8'),
         OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML);
    END;
    CREATE TABLE TEST_XML_TABLE
      ENV_CONSULT  SYS.XMLTYPE,
      MSG_TSTAMP   TIMESTAMP(6) WITH TIME ZONE      DEFAULT SYSTIMESTAMP          NOT NULL
    XMLTYPE COLUMN ENV_CONSULT STORE AS SECUREFILE BINARY XML
    (       TABLESPACE PARTYMS10_DATA
      INDEX(TABLESPACE PARTYMS10_INDEX)
    XMLSCHEMA "envelope-consult.xsd" ELEMENT "envelope"
       DISALLOW NONSCHEMA
    TABLESPACE PARTYMS10_DATA
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING
    /And here is the offending statement, together with the reported error
    INSERT
      INTO TEST_XML_TABLE
    VALUES (XDBURITYPE('/public/xmlfiles/EORI/TestXML.xml').getXML(), SYSTIMESTAMP)
    COMMIT
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LSX-00213: only 0 occurrences of particle "abstract.ref", minimum is 1
    Details:
    INSERT
      INTO TEST_XML_TABLE
    VALUES (XDBURITYPE('/public/xmlfiles/EORI/TestXML.xml').getXML(), SYSTIMESTAMP)
    Error at line 1
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LSX-00213: only 0 occurrences of particle "abstract.ref", minimum is 1I am using 11.1.0.7.0, as seen on
    select * from v$version;
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production         
    PL/SQL Release 11.1.0.7.0 - Production                                         
    CORE   11.1.0.7.0   Production                                                     
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production                        
    NLSRTL Version 11.1.0.7.0 - Production                                         
    5 rows selected.Any ideas ? I cannot understand it at all... It seems to relate to the substitutionGroup entries in general, but I can't for the life of me see why :(
    Best Regards
    Philip

  • SAX Parser Validation Bug or.....

    I'm using Oracle XML Parser 2.0.1.0.0 for C Programming.
    I found that the parser cannot provide validation function when it use the SAX parser.
    I try to use a different tag name between the data. It also can pass the parser
    example:<nam>John<name>
    As W3C XML 1.0 standard, All data must be pack by a pair of SAME tag.
    Is it a limitation or bug of SAX parser ?
    Thanks
    Sanjaya
    null

    Hi,
    This is indeed a bug in our parser. It has been fixed and will be available in OTN with the next release.
    Thank you,
    Oracle XML Team

  • SAX Parser Validation with Schemas (C, C++ and JAVA)

    We are currently using the Oracle XML Parser for C to parse and validate XML data using the SAX parser interface with validation turned on. We currently define our XML with a DTD, but would like to switch to schemas. However, the Oracle XML Parser 9.2.0.3.0 (C) only validates against a DTD, not a schema when using the SAX interface. Are there plans to add schema validation as an option? If so, when would this be available? Also, the same limitation appears to be true for C++ and JAVA. When will any of these provide SAX parsing with schema validation?
    Thanks!
    John

    Will get back to you after checked with development team...

  • XML creation/parsing/validation & performance

    Hello friends. I'm faced with a situation in which I need to create and parse many relatively small xml documents. Most of the XML I will be exchanging is very simple, such as:
    <? xml version="1.0"?>
    <transactionId>12345</transactionId>
    <accountId>98765</accountId>
    <address>123 Main Street</address>
    I have done enough research and prototyping to create and parse these simple documents using the DOM model. I have really started to wonder if I'd be better of simply hardcoding the creation and parsing of these documents. I'm getting some of these documents as a String over HTTP and then creating a DOM which I then can parse and am just not sure if what I am gaining in good programming practice is worth incurring the overhead of the DOM creation and parsing process.
    I'm even more divided on the issue of using DTDs or XML Schemas to validate the structure of these tiny documents. I will be having to exchange a lot of these tiny XML messages and am comfortable with the fact that the parties I am trading XML with are not going to be changing things up on the fly.
    On the other hand, I am a beginner in the XML world and am sure there could be a hundred things I haven't thought off.
    I am grateful for any assistance.
    CM

    Also,
    I assume that the values in you XML document are values from Java Objects, so why not have an interface defining a "toXml()" method for application classes to implement. All the classes would need to do is to know how to write its properties (variables) to an XML document. Again JDOM can handle his very easily... see below code....
    /** method to return the entity properties as an XML string.
    * @return the objects properties in an XML document String.
    public String toXml() {
    XMLOutputter out = null;
    String xml = null;
    Document document = new Document(new Element( "gallery-xml" ));
    Element root = document.getRootElement();
    Element content = new Element("gallery");
    content.addContent(new Comment("Details of Gallery as an XML document"));
    * Add attributes to xml document
    DateFormat format = DateFormat.getDateInstance();
    content.addContent(new Element( "image-id" ).addContent( getUUID() ));
    content.addContent(new Element( "name" ).addContent( this.getImageName() ));
    content.addContent(new Element( "student-name" ).addContent( this.getStudentName() ));
    //content.addContent(new Element( "image-bytes" ).addContent( new String(this.getImageBytes()) ));
    content.addContent(new Element( "image-file" ).addContent( this.getImageFile() ));
    content.addContent(new Element( "date-created" ).addContent( format.format( this.getDateCreated() )));
    content.addContent(new Element( "description" ).addContent( this.getDescription() ));
    content.addContent(new Element( "subset" ).addContent( this.getSubset() ));
    content.addContent(new Element( "year" ).addContent( this.getYear() ));
    content.addContent(new Element( "course-id" ).addContent( this.getCourseId() ));
    root.addContent( content );
    //write to a string
    out = new XMLOutputter(" ", true);
    xml = out.outputString(document);
    if (Logger.DEBUG) System.out.println( out.outputString( document ) );
    return xml;

  • DateFormat.parse(String)

    can anybody tell me why I don't get a SHORT format:
    import java.util.*;
    import java.text.*;
    public class MyDate{
       public static void main(String[] args){
          Date date = makeDate("04/22/2003");
          System.out.println(date); // what i get looks more like FULL
        public static Date makeDate(String dateString){
           Date date = null;
           try {
              DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
              date = fmt.parse(dateString);
          catch(ParseException e) {}
          return date;
    }Thank you.

    what I think is tripping you up is that a java.util.Date is not a String. It looks like you're thinking that you can format a java.util.Date object and somehow it is "11/23/2004" (or whatever) - but it's not - it's just a number. So, you have this String that you want to convert to a java.util.Date (which you correctly did with the parse method of the DateFormat class) but then you turn around and want to convert that java.util.Date to a String so you can put it into a List, so why not just put the original String into your List? Is it because you want to change the format? Fair enough, then you can use two DateFormat implementations, one to parse the incoming String to a Date, then the other to format the Date to the format you want. Or is it so you can do the sort chronologically? If that's the case, then you can write up a Comparator to do that, or you can store Dates in your list, sort them, and when it comes time to display this thing (if you ever do that) use a DateFormat implementation to convert those to a formatted String.
    Make sense?

  • DateFormat parse problem

    Hello all,
    I'm trying to parse a simple date, using java version 1.4.12, but for some reason an exception is thrown. Here is the code:
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    Date date = format.parse("Nov 4, 2003 8:14 PM");
    Can anyone help?
    Thanks

    I always use SimpleDateFormat. One thing might be that the parsing pattern returned for your default locale doesn't match your input String.

  • How to change dateformat of VALID FROM and VALID TO properties in xml forms

    Hi all,
                I have created a news using xml form bulider and i have given lifetime for that news ,also displaying the VALID FROM and VALID TO  in news.By default it is in mm.dd.yyyy format but i need to display the dateformat as dd.mm.yyyy in show form.Is there any possiblity to change the format in XSLT or any other solutions.
    Regards
    Bala

    Hi Bala
    Check this XML FORMS - Date Format.
    Its a quite easy way.
    Regards
    BP

  • XML parser validation and startup class

    When I try to run run jCOM bridge like a startup class, I have the following error:
    *** Loading bridge; Please wait ***
    *** Bridge loaded successfully ***
    Looking for BEA WebLogic 6.1 license...
    Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired. Parser will use a default
    ErrorHandler to print the first 10 errors. Please call
    the 'setErrorHandler' method to fix this.
    Error: URI=file:d:/bea61sp1/registry.xml Line=3: Element type "bea-product-infor
    mation" is not declared in the dtd or schema.
    Error: URI=file:d:/bea61sp1/registry.xml Line=4: Element type "host" is not decl
    ared in the dtd or schema.
    Error: URI=file:d:/bea61sp1/registry.xml Line=5: Element type "product" is not
    d
    eclared in the dtd or schema.
    Error: URI=file:d:/bea61sp1/registry.xml Line=6: Element type "release" is not
    d
    eclared in the dtd or schema.
    Error: URI=file:d:/bea61sp1/registry.xml Line=7: Element type "component" is not
    declared in the dtd or schema.
    Error: URI=file:d:/bea61sp1/registry.xml Line=8: Element type "component" is not
    declared in the dtd or schema.
    BEA WebLogic 6.1 license found...
    It seems that the XML validation of the license file falls in error because I
    don't use the right XML parser.
    Could you tell me which is the right XML parser to use when I launch the jCOM
    bridge launches ?
    Besides, is it possible to give a parser class to the bridge class with properties,
    like with JAXP via option -D.... in the line command ?
    Thanks.
    Richard

    There are two oracle_xmlparserv2.jar in your classpath? Would you make sure the correct version is used?

  • Problem with DateFormat.parse

    hi,
    I'm working using Java 1.5.
    i'm using SimpleDateFormat to parse date strings. My program has the following piece of code:
    Class DateConverter {
    SimpleDateFormat m_sdate = null ;
    public DateConverter() {
    this.m_sdate = new SimpleDateFormat("yyyyMMdd") ;
    public Date to_date(String dstr) {
    return this.m_sdate.parse(dstr) ;
    The date parsing works fine as long as I give dates upto "00010101" but throws java.text.ParseException for the value "00001231". I was just eager to know whether 00010101 is the least date that can be parsed???
    Thanks,
    Venkatesh

    I don't get a ParseException with your code; if there is an earliest date that can be parsed it's not 1/1/1.fmt = new SimpleDateFormat("yyyy/MM/dd");
    new SimpleDateFormat("dd.MM.y G").format(fmt.parse("0/12/31"));
    output: <31.12.01 BC>

Maybe you are looking for

  • Error while using ozf_fund_utilized_pub.create_fund_adjustment

    Hi I am using ozf_fund_utilized_pub.create_fund_adjustment in order to create entries in ozf_funds_utilized_all_b table. In order to achieve the same I am using the below code. I have given the required explanation for each parameter alongwith. DECLA

  • Caller identification with your online number in s...

    Hi guys, was wondering if it is possible to set my caller identification to my Skype online number in stead of my mobile number.  I'm using it for business and would like people to call me back on my skype line in stead of on my personal mobile Thank

  • Dreamweaver connection issues

    Hi all, Over the past couple of weeks I am having increasing difficulty with Dreamweaver trying to connect to BC sites when I am ftpingto the extent I am having to restart DW after closing it down via Task Manager.  It is now on virtually every new f

  • Passed hardware test, won't boot

    I am trying to get my 2008 iMac running again.  I replaced the hard drive after it quit working.  I have the boot cd in and when I ran the hardware test there were No issues.  All that I get is the missing file (flashing question mark) screen.  I can

  • The connected AC adapter has a lower wattage than the recommended model which...

    The connected AC adapter has a lower wattage than the recommended model which was shipped with the system. To boot with the AC adapter, please connect the AC adapter which was shipped with the system. Press Esc to continue. This is the message I get