Is parser provided by java validating??

I have jdk 1.4 on my machine and was wondering if the parser provided is a validating parser?
I ran a program with an XML file, using a DTD for validation, that had text in an element that was declared as EMPTY. I didnt get any errors. I was expecting them. Can anyone explain why this is happening?
Also is there any advantage of using the Apache xerces parser over the parser provided by java.
thanks in advance

have you setValidating(true) on your DocumentBuilderFactory?

Similar Messages

  • How to parse XML to Java object... please help really stuck

    Thank you for reading this email...
    If I have a **DTD** like:
    <!ELEMENT person (name, age)>
    <!ATTLIST person
         id ID #REQUIRED
    >
    <!ELEMENT name ((family, given) | (given, family))>
    <!ELEMENT age (#PCDATA)>
    <!ELEMENT family (#PCDATA)>
    <!ELEMENT given (#PCDATA)>
    the **XML** like:
    <person id="a1">
    <name>
         <family> Yoshi </family>
         <given> Samurai </given>
    </name>
    <age> 21 </age>
    </person>
    **** Could you help me to write a simple parser to parse my DTD and XML to Java object, and how can I use those objects... sorry if the problem is too basic, I am a beginner and very stuck... I am very confuse with SAXParserFactory, SAXParser, ParserAdapter and DOM has its own Factory and Parser, so confuse...
    Thank you for your help, Yo

    Hi, Yo,
    Thank you very much for your help. And I Wish you are there...I'm. And I plan to stay - It's sunny and warm here in Honolulu and the waves are up :)
    A bit more question for dear people:
    In the notes, it's mainly focus on JAXB,
    1. Is that mean JAXB is most popular parser for
    parsing XML into Java object? With me, definitely. There are essentially 3 technologies that allow you to parse XML documents:
    1) "Callbacks" (e.g. SAX in JAXP): You write a class that overrides 3 methods that will be called i) whenever the parser encounters a start tag, ii) an end tag, or iii) PCDATA. Drawback: You have to figure out where the heck in the document hierarchy you are when such a callback happens, because the same method is called on EACH start tag and similarly for the end tag and the PCDATA. You have to create the objects and put them into your own data structure - it's very tedious, but you have complete control. (Well, more or less.)
    2) "Tree" (e.g. DOM in JAXP, or it's better cousin JDOM): You call a parser that in one swoop creates an entire hierarchy that corresponds to the XML document. You don't get called on each tag as with SAX, you just get the root of the resulting tree. Drawback: All the nodes in the tree have the same type! You probably want to know which tags are in the document, don't you? Well, you'll have to traverse the tree and ask each node: What tag do you represent? And what are your attributes? (You get only strings in response even though your attributes often represent numbers.) Unless you want to display the tree - that's a nice application, you can do it as a tree model for JTree -, or otherwise don't care about the individual tags, DOM is not of much help, because you have to keep track where in the tree you are while you traverse it.
    3) Enter JAXB (or Castor, or ...): You give it a grammar of the XML documents you want to parse, or "unmarshall" as the fashion dictates to call it. (Actually the name isn't that bad, because "parsing" focuses on the input text while "unmarshalling" focuses on the objects you get, even though I'd reason that it should be marshalling that converts into objects and unmarshalling that converts objects to something else, and not vice versa but that's just my opinion.) The JAXB compiler creates a bunch of source files each with one (or now more) class(es) (and now interfaces) that correspond to the elements/tags of your grammar. (Now "compiler" is a true jevel of a misnomer, try to explain to students that after they run the "compiler", they still need to compile the sources the "compiler" generated with the real Java compiler!). Ok, you've got these sources compiled. Now you call one single method, unmarshall() and as a result you get the root node of the hierarchy that corresponds to the XML document. Sounds like DOM, but it's much better - the objects in the resulting tree don't have all the same type, but their type depends on the tag they represent. E.g if there is the tag <ball-game> then there will be an object of type myPackage.BallGame in your data structure. It gets better, if there is <score> inside <ball-game> and you have an object ballGame (of type BallGame) that you can simply call ballGame.getScore() and you get an object of type myPackage.Score. In other words, the child tags become properties of the parent object. Even better, the attributes become properties, too, so as far as your program is concerned there is no difference whether the property value was originally a tag or an attribute. On top of that, you can tell in your schema that the property has an int value - or another primitive type (that's like that in 1.0, in the early release you'll have to do it in the additional xjs file). So this is a very natural way to explore the data structure of the XML document. Of course there are drawbacks, but they are minor: daunting complexity and, as a consequence, very steep learning curve, documentation that leaves much to reader's phantasy - read trial and error - (the user's guide is too simplicistic and the examples too primitive, e.g. they don't even tell you how to make a schema where a tag has only attributes) and reference manual that has ~200 pages full of technicalities and you have to look with magnifying glas for the really usefull stuff, huge number of generated classes, some of which you may not need at all (and in 1.0 the number has doubled because each class has an accompanying interface), etc., etc. But overall, all that pales compared to the drastically improved efficiency of the programmer's efforts, i.e. your time. The time you'll spend learning the intricacies is well spent, you'll learn it once and then it will shorten your programming time all the time you use it. It's like C and Java, Java is order of magnitude more complex, but you'd probably never be sorry you gave up C.
    Of course the above essay leaves out lots and lots of detail, but I think that it touches the most important points.
    A word about JAXB 1.0 vs. Early Release (EA) version. If you have time, definitively learn 1.0, they are quite different and the main advantage is that the schema combines all the info that you had to formulate in the DTD and in the xjs file when using the EA version. I suggested EA was because you had a DTD already, but in retrospect, you better start from scratch with 1.0. The concepts in 1.0 are here to stay and once your surmounted the learning curve, you'll be glad that you don't have to switch concepts.
    When parser job is done,
    what kind of Java Object we will get? (String,
    InputStream or ...)See above, typically it's an object whose type is defined as a class (and interface in 1.0) within the sources that JABX generates. Or it can be a String or one of the primitive types - you tell the "compiler" in the schema (xjs file in EA) what you want!
    2. If we want to use JAXB, we have to contain a
    XJS-file? Something like:In EA, yes. In 1.0 no - it's all in the schema.
    I am very new to XML, is there any simpler way to get
    around them? It has already take me 4 days to find a
    simple parser which give it XML and DTD, then return
    to me Java objects ... I mean if that kind of parser
    exists....It'll take you probably magnitude longer that that to get really familiar with JAXB, but believe me it's worth it. You'll save countless days if not weeks once you'll start developing serious software with it. How long did it take you to learn Java and it's main APIs? You'll either invest the time learning how to use the software others have written, or you invest it writing it yourself. I'll take the former any time. But it's only my opinion...
    Jan

  • Parse xml file with validating againat dtd

    i have a xlm file looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE map SYSTEM "map.dtd">
    <map width="20" height="15" goal="25" name="eXtreme Labyrinth of Dooom">
    <random-item type='lantern' amount='5' />
    <random-item type='health' amount='10' />
    <tile x="14" y="0" type="wall">
    <renderhint>wall:rock,cracked</renderhint>
    </tile>
    <tile x="15" y="0" type="wall" />
    <tile x="16" y="0" type="floor">
    <renderhint>floor:marble,cracked</renderhint>
    </tile>
    <tile x="17" y="0" type="floor">
    <renderhint>floor:stone,rubble</renderhint>
    </tile>
    <tile x="18" y="0" type="floor" />
    <tile x="0" y="1" type="floor" />
    <tile x="1" y="1" type="floor" startlocation="1" />
    <tile x="2" y="1" type="floor" />
    <tile x="3" y="1" type="floor">
    <item type="treasure">Bar of Silver</item>
    <renderhint>floor:stone,blood</renderhint>
    </tile>
    <tile x="4" y="1" type="wall" />
    <tile x="5" y="1" type="wall" />
    <tile x="6" y="1" type="wall">
    <renderhint>wall:bricks,cracked</renderhint>
    </tile>
    </map>and a dtd document like:
    <!ELEMENT map (random-item+, tile+)>
    <!ATTLIST map
    width CDATA #REQUIRED
    height CDATA #REQUIRED
    goal CDATA #REQUIRED
    name CDATA #REQUIRED
    <!ELEMENT random-item EMPTY>
    <!ATTLIST random-item
    type (armour|health|sword|treasure|lantern) #REQUIRED
    amount CDATA #REQUIRED
    <!ELEMENT tile (item|renderhint)*>
    <!ATTLIST tile
    x CDATA #REQUIRED
    y CDATA #REQUIRED
    type (exit|floor|wall) #REQUIRED
    startlocation CDATA #IMPLIED
    <!ELEMENT item (#PCDATA)>
    <!ATTLIST item
    type (armour|health|sword|treasure|lantern) #REQUIRED
    <!ELEMENT renderhint (#PCDATA)>i need to validate the xml file against the dtd document and parse it to java using DOM.
    Can anyone give ma any suggestions on how to do it?
    thank you

    i have started my coding like:
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    import java.io.*;
    class loadxml
        public static void main(String[] args)
         try {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setValidating(true);
              factory.setIgnoringElementContentWhitespace(true);
              DocumentBuilder parser = factory.newDocumentBuilder();
              Document doc = parser.parse(new File("hallways.xml"));
              loadxml load = new loadxml();
              load.parseNode(doc);
         } catch (ParserConfigurationException e) {
              e.printStackTrace();
         } catch (SAXException e) {
              e.printStackTrace();
         } catch (IOException e) {
              e.printStackTrace();
        public void parseNode (Node node) throws IOException
               // here is where i have problem with
    }since in my xml file, i have got ATTLIST, this ready confuses me when i try to coding it.
    Can anyone help me, please.
    Thank you.
    Edited by: mujingyue on Mar 12, 2008 3:10 PM

  • Provide the java code for the following scenario.

    Hi Experts,
    I have tried with all the combinations for this scenario. As per my understanding i require java code for the following scenario
    so that it becomes easy........
    I require a Message mapping for this Logic.
    In the Source there are 4 fields and, the Target side, the fields should appear like this.
    Source Structure- File
    Record
    |-> Header
    Order_No
    Date
    |-> Item
    Mat_No
    Quantity
    Target Structure-IDoc
    IDoc
    |-> Header
    |-> Segment
    Delivery_Order_No
    Recv_Date
    |-> Item
    |-> Segment
    Delivery_Order_No
    Material_Num
    Recv_Quantity.
    The Logic is for every Order number an IDOC is generated.And if the Material num matches then the quantity should be added. and important note is that the material numbers are different for every order number. That means if a material number is 2 in the order number A. Then the material number can never be 2 in any of the order numbers.Here is the following with an example for the above scenario.
    For example:-
    we have
    Source Structure- File
    Order-no Date Mat_No Quantity
    1 01/02/2011 A 10
    1 01/02/2011 B 15
    1 01/02/2011 A 10
    2 01/02/2011 C 10
    2 01/02/2011 C 10
    3 01/02/2011 D 20
    3 01/02/2011 D 10
    3 01/02/2011 E 25
    Target Structure-IDoc
    Delivery_Order_No Recv_Date Material_Num Recv_Quantity
    1 01/02/2011 A 20
    1 01/02/2011 B 15
    2 01/02/2011 C 20
    3 01/02/2011 D 30
    3 01/02/2011 E 25
    So for this example total of 5-Idocs created. That means for this example if Order_No is 1 When the Mat_No is A the quantity gets added. For this Scenario 1 IDoc with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) is generated by adding the quantity field in the Target Side. Similarly if Order_No is 1 when the Mat_No is B then separate IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) in the Target Side. Similarly, if Order_No is 2 when the Mat_No is C, an IDoc is generated with four Fields 2 in Header(Delivery_Order_No, Recv_Date) and 2 in Item(Material_Num, Recv_Quantity) by adding the quantity field in the Target Side. ike wise the process goes on upto 3.Kindly do the needy..
    Kindly provide the java code.
    Thanq very much in advance..

    what i have understood from ur example is that u want to generate an idoc for unique combination of  Order-no and Mat_No
    if yes then chk the below mapping..
    change the context of Order_No, Date, Mat_No and Quantity to Record (right click-> context)
    1)
    Order-no
    ----------------------concat[;]---sort----splitbyvalue(valuechanged)-----collapse context---IDoc
    Mat_No
    2)
    Order-no
    --------concat[;]---sort----splitbyvalue(value changed)---collapse context---UDF1--splitbyvalue(each value)--Delivery_Order_No
    Mat_No
    3)
    Order-no
    -----------concat[;]---sortbykey----------------------- \
    Mat_No                       /                            \
    Date--------------- /                                       \
    ----------------------------------------------------------FormatByExample-----collapsecontext---splitbyvalue(each value)----Recv_Date
    Order-no                                                 /
    -----------concat[;]---sort----splitbyvalue(value changed)
    Mat_No
    4)
    Order-no
    --------concat[;]---sort----splitbyvalue(value changed)---collapse context-UDF2--splitbyvalue(each value)--Material_Num
    Mat_No
    5)
    Order-no
    -----------concat[;]---sortbykey
    Mat_No                       /
    Quantity --------------- /
    ----------------------------------------------------------FormatByExample-----SUM(under statistic)----Recv_Quantity
    Order-no
    -----------concat[;]---sort----splitbyvalue(value changed)
    Mat_No
    UDF1:
    String [] temp= a.split(";");
    return temp[0];
    UDF2:
    String [] temp= a.split(";");
    return temp[1];

  • "The file destination provided is not valid. Enter a valid location."

    I'm running Acrobat 9, with all updates installed, on Win XP.
    I have used shared review before, and it worked. I click Comments, Send for Shared Review.
    When I try to initiate a shared review, I browse to select my pdf, click on the filename, and I immediately get this error message: The file destination provided is not valid. Enter a valid location.
    I have tried accessing a file on a shared network behind my company's firewall, on my local hard drive, and my desktop. All three locations generate the exact same error.
    I know the "source" file and the "shared" file have to be in two separate locations. The error message is occuring BEFORE I can specify anything else.
    Any and all help is greatly appreciated!

    I can share a document on Acrobat.com (I just verified this), but I can't send one for shared review. Same error message as before. Curiouser and curiouser!
    Date: Wed, 31 Mar 2010 08:13:29 -0600
    From: [email protected]
    To: [email protected]
    Subject: "The file destination provided is not valid. Enter a valid location."
    Has the version of Acrobat that you're using been packaged by your IT department? If so, can you find out if they perhaps disabled access to Acrobat.com. Sometimes in doing this, shared reviews are inadvertently disabled.
    >

  • Problems using NSS library as PKCS#11 provider with JAVA 6

    Hi,
    I�m trying to configure JAVA 6 on Solaris 10 SPARC to use Mozilla NSS library as PKCS#11 provider (to achieve FIPS-140 certification for my application). I�m following the guidelines from http://java.sun.com/javase/6/docs/technotes/guides/security/p11guide.html#NSS but unfortunately something doesn�t work for me as expected...
    Let me describe the exact steps that I followed (because devil may be in the small details :-)
    I downloaded NSS 3.11.4 and NSPR 4.6.4 binaries from mozilla.org (32 bit �debug� versions for Solaris 9, because these were the only �binary� versions for SPARC available on Mozilla site and as far as I understand these are the exact versions that passed FIPS-140 certification), unpacked them under the /opt directory and copied both of them into a single /opt/nss tree as follows:
    mkdir /opt/nss
    cp �r /opt/nss-3.11.4/* /opt/nss
    cp �r /opt/nspr-4.6.4/* /opt/nss
    I created a PKCS#11 configuration file /opt/nss/pkcs11.cfg as per JAVA 6 security guide:
    name = NSScrypto
    nssLibraryDirectory = /opt/nss/lib
    nssDbMode = noDb
    attributes = compatibility
    (I know that this configuration is not for FIPS mode � but I thought that I�d better start with a simple NSS configuration)
    Then I modified /usr/jdk/jdk1.6.0_03/jre/lib/security/java.security file and replaced 1st provider with:
    security.provider.1=sun.security.pkcs11.SunPKCS11 /opt/nss/pkcs11.cfg
    Now everything should be in place � so I created a small JAVA program and ran it:
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.DESedeKeySpec;
    import javax.crypto.SecretKey;
    import javax.crypto.Cipher;
    import java.security.*;
    public class Test
    public static void main(String[] args)
    try
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
    DESedeKeySpec keySpec = null;
    keySpec = new DESedeKeySpec(new String("laKuf1Tcc6sOhsdPf49=m4es").getBytes());
    System.out.println("keyFactory provider: " + keyFactory.getProvider().getName());
    SecretKey key = keyFactory.generateSecret(keySpec);
    Cipher decryptCipher = Cipher.getInstance("DESede");
    decryptCipher.init(Cipher.DECRYPT_MODE, key);
    System.out.println("decryptCipher provider: " + decryptCipher.getProvider().getName());
    catch (Exception ex)
    ex.printStackTrace();
    Unfortunately it produced the following output:
    EMS-Server42# java test
    keyFactory provider: SunPKCS11-NSScrypto
    decryptCipher provider: SunJCE
    And when I comment out SunJCE provider in java.security file I get the following exception:
    java.security.NoSuchAlgorithmException: Cannot find any provider supporting DESede
    at javax.crypto.Cipher.getInstance(DashoA13*..)
    at test.main(test.java:38)
    So it looks like something is wrong with my NSS configuration. Because AFAIK DESede (3DES) is supported by the NSS library, but for some reason JAVA doesn�t see this algorithm implemented in NSS PKCS#11 provider.
    Any suggestions on what am I doing wrong?
    Best regards,
    Alex

    Works for me:
    import java.security.Provider;
    import java.security.SecureRandom;
    import java.security.Security;
    import javax.crypto.Cipher;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.DESedeKeySpec;
    import javax.crypto.spec.IvParameterSpec;
    public class Test
      public static void main(String[] args)
        try
          String configFileName = "/nss/nss.cfg";
          Provider nss = new sun.security.pkcs11.SunPKCS11(configFileName);
          Security.addProvider(nss);
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede", nss);
          DESedeKeySpec keySpec = new DESedeKeySpec(new String("laKuf1Tcc6sOhsdPf49=m4es").getBytes("UTF-8"));
          System.out.println("keyFactory provider: " + keyFactory.getProvider().getName());
          SecretKey key = keyFactory.generateSecret(keySpec);
          //iv for CBC mode - note, in practice you don't generate a random iv for decryption :)
          byte[] iv = new byte[8];  //64-bit block size for 3DES
          SecureRandom sr = SecureRandom.getInstance("PKCS11", nss);
          sr.nextBytes(iv);
          IvParameterSpec params = new IvParameterSpec(iv);
          Cipher decryptCipher = Cipher.getInstance("DESede/CBC/NoPadding", nss);
          decryptCipher.init(Cipher.DECRYPT_MODE, key, params);
          System.out.println("decryptCipher provider: " + decryptCipher.getProvider().getName());
        catch (Exception ex)
          ex.printStackTrace();
    }Oh, I wouldn't expect your key loading to work when you switch over to FIPS mode.
    cfg file:
    name = NSScrypto
    nssLibraryDirectory = /nss
    nssSecmodDirectory = /nss
    nssModule = fipsYields the following error:
    java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: Could not create key
    because you can't directly handle keying material in FIPS. You'll have to save the secret key in the NSS certDB or generate a random one each time and send it wrapped to the other side.

  • How to call Java Validations from MDM Workflow

    We have some Java Validations which have to be triggerd from the Workflow.
    We do <b>NOT</b> want to use the Enrichment Framework for doing this.
    How can we call these Java Validations from the Workflow?

    Hi Adhappan,
    As I see, these kinds of validations are not possible as of now. I'm not very sure if VISIO internally can refer to the JAVA validations, but otherwise this is not possible with current version of the product.
    Regards,
    Mausam

  • Can I use a C/C++ xml parser in my java program?

    Hi,
    How can I use a C/C++ xml parser in my java program?
    Elvis.

    You would still need to convert the XML data structure into a Java data structure to import it into Java.
    Don't assume you need C++ to do anything. I woudl write it in Java first, then profile the application to see where the bottle necks are and then optimise them
    Don't optimise code unless you have proof it needs to be optimised.
    If you want to improve the speed of reading XML, try XMLbooster

  • Hello , I have a license CS6 4 posts (3 installed on PC) I just got a mac so I wanted to install the latest license it but when I want to register on the site adobe it tells me that " the number provided is not valid "can help me thank you

    Hello , I have a license CS6 4 posts (3 installed on PC) I just got a mac so I wanted to install the latest license it but when I want to register on the site adobe it tells me that " the number provided is not valid "can help me thank you

    Contact support by web chat.
    Mylenium

  • Java Validation Framework

    Hi,
    Is there any Validation Framework avail for validating a Form,i am expecting this framework will be a plugin,so i can change the validation at any time,without building the application everytime, so we can configure different validations for different projects, without changing the build.
    I searched the net & find out Rule Engine ( Ex: Drools ) can do this, is there any other framework available..?
    Thx.

    There is the general Java validation JSR, of which [Hibernate Validator|http://www.hibernate.org/subprojects/validator.html] is a populate implementation. Your actual MVC framework also undoubtedly has a validator API.
    - Saish

  • ADDRESS parse error in java mail

    Hi,
    I'm trying to retrieve the mails header and I get following error.
    javax.mail.MessagingException: Failed to load IMAP envelope: foldername=INBOX[uidvalidity:1222323518] : seqnum=1
    After digging source code of java mail I found that one of bad address is causing this problem. One of message is having following format of address.
    ("test" R "test" NIL "test1" "test.net.au").
    According to specifications (RFC 2060) address should have four component personal name, [SMTP] at-domain-list (source route), mailbox name, and host name. When java mail tries parse this address it throws address parsing exception.
    Is anyone have come across this issue? I want to know is there any way to handle this scenario. Since other mail client seems to handle it e.g. thunderbird
    Regards
    Anupriya

    I'm using java mail 1.4.1. I downloaded the code from https://glassfish.dev.java.net/javaee5/mail//index.html and I haven't made any changes to code.
    I'm running msgshow.java program. I'm not running in any app server or web server.
    and following is output from program as i was mentioning earlier it's happening when I try to get the size of the message.
    DEBUG: setDebug: JavaMail version 1.4.1
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
    DEBUG: mail.imap.fetchsize: 16384
    * OK IMAP4 server (InterMail vM.7.05.02.03 201-2174-114-109-20070208) ready Tue, 25 Nov 2008 04:22:06 +0000 (GMT)
    A0 CAPABILITY
    * CAPABILITY IMAP4rev1 UIDPLUS NAMESPACE QUOTA
    A0 OK CAPABILITY completed
    DEBUG: protocolConnect login, host=test.com, [email protected], password=<non-null>
    A1 LOGIN [email protected] pass
    A1 OK LOGIN completed
    A2 CAPABILITY
    * CAPABILITY IMAP4rev1 UIDPLUS NAMESPACE QUOTA
    A2 OK CAPABILITY completed
    DEBUG: connection available -- size: 1
    A3 SELECT INBOX
    * 24 EXISTS
    * OK [UIDVALIDITY 1222323518] UIDs valid
    * OK [UIDNEXT 1031] Predicted next UID
    * FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
    * OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted \Draft \Seen)] Permanent flags
    * 0 RECENT
    A3 OK [READ-WRITE] SELECT completed
    Getting message number: 20
    A4 FETCH 20 (BODY[])
    * 20 FETCH (BODY[] {569}
    Return-Path: <[email protected]>
    Received: from [127.0.0.1] by nssas01t.mx.test.com
    (InterMail vM.7.05.02.08 201-2174-114-118-20080528) with SMTP
    id <20071127054828.IKXY25226.nssas01t.mx.test.com@[127.0.0.1]>
    for <[email protected]>; Mon, 17 Nov 2008 05:48:28 +0000
    Date: Mon, 7 Feb 2008 21:52:25 -0800 (PST)
    From: "Test" R "Us"<[email protected]>
    Subject: afternoon meeting 1
    To: [email protected]
    Message-Id: <20071127054828.IKXY25226.nssas01t.mx.test.com@[127.0.0.1]>
    Hello
    A4 OK FETCH completed
    Return-Path: <[email protected]>
    Received: from [127.0.0.1] by nssas01t.mx.test.com
    (InterMail vM.7.05.02.08 201-2174-114-118-20080528) with SMTP
    id <20071127054828.IKXY25226.nssas01t.mx.test.com@[127.0.0.1]>
    for <[email protected]>; Mon, 17 Nov 2008 05:48:28 +0000
    Date: Mon, 7 Feb 2008 21:52:25 -0800 (PST)
    From: "Test" R "Us"<[email protected]>
    Subject: afternoon meeting 1
    To: [email protected]
    Message-Id: <20071127054828.IKXY25226.nssas01t.mx.test.com@[127.0.0.1]>
    Hello
    A5 FETCH 20 (FLAGS)
    * 20 FETCH (FLAGS (\Seen))
    A5 OK FETCH completed
    A6 FETCH 20 (ENVELOPE INTERNALDATE RFC822.SIZE)
    * 20 FETCH (ENVELOPE ("Mon, 7 Feb 2008 21:52:25 -0800 (PST)" "afternoon meeting 1" (("Test" R "Us" NIL "auto_786" "test.com")) (("Test" R "Us" NIL "auto_786" "test.com")) (("Test" R "Us" NIL "auto_786" "test.com")) ((NIL NIL "auto_786" "test.com")) NIL NIL NIL "<20071127054828.IKXY25226.nssas01t.mx.test.com@[127.0.0.1]>") INTERNALDATE "17-Nov-2008 05:48:46 +0000" RFC822.SIZE 569)
    A6 OK FETCH completed
    Oops, got exception! Failed to load IMAP envelope
    javax.mail.MessagingException: Failed to load IMAP envelope
         at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1226)
         at com.sun.mail.imap.IMAPMessage.getSize(IMAPMessage.java:387)
         at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:229)
         at msgshow.main(msgshow.java:232)

  • Persisting unexplained errors when parsing XML with schema validation

    Hi,
    I am trying to parse an XML file including XML schema validation. When I validate my .xml and .xsd in NetBeans 5.5 beta, I get not error. When I parse my XML in Java, I systematically get the following errors no matter what I try:
    i) Document root element "SQL_STATEMENT_LIST", must match DOCTYPE root "null".
    ii) Document is invalid: no grammar found.
    The code I use is the following:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    My XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- Defining the SQL_STATEMENT_LIST element -->
    <xs:element name="SQL_STATEMENT_LIST" type= "SQL_STATEMENT_ITEM"/>
    <xs:complexType name="SQL_STATEMENT_ITEM">
    <xs:sequence>
    <xs:element name="SQL_SCRIPT" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <!-- Defining simple type ApplicationType with 3 possible values -->
    <xs:simpleType name="ApplicationType">
    <xs:restriction base="xs:string">
    <xs:enumeration value="DawningStreams"/>
    <xs:enumeration value="BaseResilience"/>
    <xs:enumeration value="BackBone"/>
    </xs:restriction>
    </xs:simpleType>
    <!-- Defining the SQL_SCRIPT element -->
    <xs:element name="SQL_SCRIPT" type= "SQL_STATEMENT"/>
    <xs:complexType name="SQL_STATEMENT">
    <xs:sequence>
    <xs:element name="NAME" type="xs:string"/>
    <xs:element name="TYPE" type="xs:string"/>
    <xs:element name="APPLICATION" type="ApplicationType"/>
    <xs:element name="SCRIPT" type="xs:string"/>
    <!-- Making sure the following element can occurs any number of times -->
    <xs:element name="FOLLOWS" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    and my XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Document : SQLStatements.xml
    Created on : 1 juillet 2006, 15:08
    Author : J�r�me Verstrynge
    Description:
    Purpose of the document follows.
    -->
    <SQL_STATEMENT_LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.dawningstreams.com/XML-Schemas/SQLStatements.xsd">
    <SQL_SCRIPT>
    <NAME>CREATE_PEERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE PEERS (
    PEER_ID           VARCHAR(20) NOT NULL,
    PEER_KNOWN_AS      VARCHAR(30) DEFAULT ' ' ,
    PRIMARY KEY ( PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITIES_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITIES (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    COMMUNITY_KNOWN_AS VARCHAR(25) DEFAULT ' ',
    PRIMARY KEY ( COMMUNITY_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITY_MEMBERS (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    PEER_ID VARCHAR(20) NOT NULL,
    PRIMARY KEY ( COMMUNITY_ID, PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_PEER_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE PEERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITIES_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITIES IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITY_MEMBERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_VIEW</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE VIEW COMMUNITY_MEMBERS_VW AS
    SELECT P.PEER_ID, P.PEER_KNOWN_AS, C.COMMUNITY_ID, C.COMMUNITY_KNOWN_AS
    FROM PEERS P, COMMUNITIES C, COMMUNITY_MEMBERS CM
    WHERE P.PEER_ID = CM.PEER_ID
    AND C.COMMUNITY_ID = CM.COMMUNITY_ID
    </SCRIPT>
    <FOLLOWS>CREATE_PEERS_TABLE</FOLLOWS>
    <FOLLOWS>CREATE_COMMUNITIES_TABLE</FOLLOWS>
    </SQL_SCRIPT>
    </SQL_STATEMENT_LIST>
    Any ideas? Thanks !!!
    J�r�me Verstrynge

    Hi,
    I found the solution in the following post:
    Validate xml with DOM - no grammar found
    Sep 17, 2003 10:58 AM
    The solution is to add a line of code when parsing:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    The errors are gone !!!
    J�r�me Verstrynge

  • Parsing XML using java DOM

    hi
    i am trying to parse a document and change a specific text value within an element althouh when i run the program it changes the nodes text however when i check the xml file it doesnt show the changes it remains the same the code that i am using is as follow iwould be greatful if any one culd help:
    //  ReplaceText.java
    // Reads intro.xml and replaces a text node.
    // Java core packages
    import java.io.*;
    // Java extension packages
    import javax.xml.parsers.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import javax.xml.transform.dom.*;
    // third-party libraries
    import org.xml.sax.*;
    import org.w3c.dom.*;
    public class ReplaceText {
       private Document document;
       public ReplaceText()
          // parse document, find/replace element, output result
          try {
             // obtain default parser
             DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
             // set parser as validating          
             factory.setValidating( true );
             // obtain object that builds Documents
             DocumentBuilder builder = factory.newDocumentBuilder();
             // set error handler for validation errors
             builder.setErrorHandler( new MyErrorHandler() );
      System.err.println( "reading" );
             // obtain document object from XML document
             File f = new File("D:/Documents and Settings/Administrator/Desktop/xml adv java bk/appC/intro.xml");
              System.err.println( "reading" );
             document = builder.parse(f);
    //document = builder.parse( new File( "intro.xml" ) );
    System.err.println( "reading document" );
             // retrieve the root node
             Node root = document.getDocumentElement();
             if ( root.getNodeType() == Node.ELEMENT_NODE ) {
                Element myMessageNode = ( Element ) root;
                NodeList messageNodes =
                   myMessageNode.getElementsByTagName( "message5" );
                if ( messageNodes.getLength() != 0 ) {
                   Node message = messageNodes.item( 0 );
                        System.out.println("iiiii");
                   // create text node
                   Text newText = document.createTextNode(
                      "New Changed Message!!" );
                   // get old text node
                   Text oldText =
                      ( Text ) message.getChildNodes().item( 0 ); 
                   // replace text
                   //message.removeChild(oldText);
                   message.replaceChild( newText, oldText );
             // output Document object
             // create DOMSource for source XML document
             Source xmlSource = new DOMSource( document );
             // create StreamResult for transformation result
             Result result = new StreamResult( System.out );
             // create TransformerFactory
             TransformerFactory transformerFactory =
                TransformerFactory.newInstance();
             // create Transformer for transformation
             Transformer transformer =
                transformerFactory.newTransformer();
             transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
               transformer.setOutputProperty( OutputKeys.STANDALONE, "yes" );
             // transform and deliver content to client
             transformer.transform( xmlSource, result );
          // handle exception creating DocumentBuilder
          catch ( ParserConfigurationException parserException ) {
             parserException.printStackTrace();
          // handle exception parsing Document
          catch ( SAXException saxException ) {
             saxException.printStackTrace();        
          // handle exception reading/writing data
          catch ( IOException ioException ) {
             ioException.printStackTrace();
             System.exit( 1 );
          // handle exception creating TransformerFactory
          catch (
             TransformerFactoryConfigurationError factoryError ) {
             System.err.println( "Error while creating " +
                "TransformerFactory" );
             factoryError.printStackTrace();
          // handle exception transforming document
          catch ( TransformerException transformerError ) {
             System.err.println( "Error transforming document" );
             transformerError.printStackTrace();
       public static void main( String args[] )
          ReplaceText replace = new ReplaceText();   
    }the xml file that i am using is as follows:
    <?xml version = "1.0"?>
    <!-- Fig. 28.10 : intro.xml             -->
    <!-- Simple introduction to XML markup   -->
    <!DOCTYPE myMessage [
         <!ELEMENT myMessage (message, message5)>
         <!ELEMENT message (#PCDATA)>
         <!ELEMENT message5 (#PCDATA)>
    ]>
    <myMessage>
         <message>welcome to the xml shhhhhushu</message>
         <message5>welcome to the xml shhhhhushu</message5>
    </myMessage>i would be greatful if some one could please help.....

    See if the Text 'oldText' actually has any text within it. Sometimes in DOM parsing, you will get something like:
    Element
       Text (blank)
       Text (actual)
       Text (blank)Whereas you would expect to receive:
    Element
       Text (actual)See if that is the case. If yes, modify your logic to iterate through the child text nodes until one with actual text inside of it (getNodeValue()) is found.
    - Saish

  • Parsing xhtml using java.util.regex

    I am parsing an XHTML file using the java.util.regex package and I am perplexed at why the following doesn�t work.
    The lines I wish to match are either like this:
    <span class="someclass"><b>Some String.</b></span></td>
    or
    Some String.</td>
    The code I use to try to achieve this is:
    Pattern somePattern = Pattern.compile(".*(<span class=\"someclass\"><b>)?(.*)[.](</b></span>)?</td>.*");
    String s = null;
    while((s = br.readLine()) != null) {
    if(somePattern.matcher(s).matches()) {
    System.out.println("0:" + eventMatcher.group(0));
    System.out.println("1:" + eventMatcher.group(1));
    System.out.println("2:" + eventMatcher.group(2));
    System.out.println("3:" + eventMatcher.group(3));
    I expect to get as output
    0:<span class="someclass"><b>Some String.</b></span></td> 1:<span class="someclass"><b>
    2:Some String
    3:</b></span>
    or
    0:Some String.</td>
    1:null
    2:Some String
    3:null
    depending on which lines provide the match as mentioned above. Instead I get:
    0:<span class="someclass"><b>Some String.</b></span></td>
    1:null
    2:(empty string)
    3:</b></span>
    or
    0:Some String.</td>
    1:null
    2:(empty string)
    3:null
    Any ideas? Thanks in advance.

    Consider the terms of ".*(<span class=\"someclass\"><b>)?(.*)[.](</b></span>)?</td>.*"
    .* - greedily collect characters
    (<span class=\"someclass\"><b>)? - optionallly collect information taht will always be matched by the previous .* pattern so will be empty.
    (.*) - greedily collect characters that will also have been swallowed by the first .* so will be empty
    [.] - a single .
    (</b></span>)? - optionally collection
    </td> - must be there
    .* - collect the rest of the charcters in the line.
    Therefore in general groups 1 and 2 will be empty because the first .* will have collected the information you wanted to capture!
    You could just make the first .* non-greedy by using .*? but this may fail for other reasons.
    So, in general terms, what are you trying to extract?

  • Parsing documents in Java called via JNI

    My native application is in C running on WinXP, and I am attempting to call an API in Java using JNI. I am quite a JNI newbie so hopefully someone can shed some light on my issue. Everytime I attempt to parse a document in Java using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true); // also tried false
    DocumentBuilder builder = factory.newDocumentBuilder();
    builder.setErrorHandler(this);
    Document document = builder.parse(new File(filename));I get an IncompatibleClassChangeError exception thrown. This happens when I parse XML, text, you name it. The Java code works fine outside of JNI. The C source snippet (minus the exception checking) looks like the following:
    testClass = (*env)->FindClass(env, "TestClass");
    testMethod = (*env)->GetMethodID(env, testClass, "test", "(Ljava/lang/String;)I");
    filename = (*env)->NewStringUTF(env, "test.xml");
    value = (*env)->CallIntMethod(env, testClass, testMethod, filename); Any suggestions would be very much appreciated.

    I believe I have found the problem, and it's (of course) an exercise in double-checking everything. It also makes me want to slay my predecessors for their confusing design choices.
    The class JNIMessage isn't in the class hierarchy of Message, though it appears to be if you're not inspecting the code closely enough. This is almost certainly the problem. I was looking in the wrong place; the JNI code is probably not suspect here.

Maybe you are looking for

  • Path not working in win xp pro, can call java but not javac !

    Hello, I just upgraded to win xp and set up the J2SDK. I have set the path variable in the environment settings. when I tried to test this by typing java from my documents directory it works all right but not the javac command, to which it gives the

  • Regarding Date Function

    Hi All, Hi i want to implement the functionality as below, if i gave the Date as Input then i have to get the Respective Timezones is it possible, if yes then can u plz produce a sample snippet of it. With Regards, Justin

  • Will a Product Key work for Mac or PC?

    Thinking about going with a Mac but wondered if I would have to buy another product key if I do since I now work on a PC. Thanks for any advice! Ken

  • MDM 7,1 Portal Content

    I have configured MDM 7.1 Portal content and I am facing issuse that I do not have control on . For example if I edit an existing record and try saving the changes it saves and automatically creates a duplicate record. If I try to duplicate a particu

  • Final CAT Pro Plugins Services cause shortcuts conflict with other softwares

    I just installed Final CAT Pro Plugins. They are useful but cause me an issue: Since they are based on Services OSx system, they remain active also in other programs, so that when I use, for instance, Logic Pro, I have some shortcuts which match the