XML file parsing/validating with xerces-j

Discussion in 'XML' started by Cigdem, Mar 16, 2005.

  1. Cigdem

    Cigdem Guest

    Hello,

    I am trying to parse the XML files that the user selects(XML files are
    on anoher OS400 system called "wkdis3"). But i am permenantly getting
    that error:

    Directory0: \\wkdis3\ROOT\home
    Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\
    You selected the file named AAA.XML
    getXmlAlgorithmDocument(): IOException Not logged in

    sun.net.ftp.FtpLoginException: Not logged in
    at sun.net.ftp.FtpClient.readReply(Unknown Source)
    at sun.net.ftp.FtpClient.issueCommand(Unknown Source)
    at sun.net.ftp.FtpClient.login(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown
    Source)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown
    Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
    Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at ParseTest.<init>(ParseTest.java:110)
    at ParseTest.main(ParseTest.java:221)

    Below is my sourcefile ParseTest.java..Does anyone any idea about how
    to fix that IOException with ftp..for validating xerces i had to set
    some feautures from an URI. I thought maybe that could be the
    reason.Any idea?

    import java.io.File;
    import java.io.IOException;
    //import java.util.HashMap;
    //import java.util.Map;

    import javax.swing.JFileChooser;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;

    //import org.apache.excalibur.source.SourceParameters;
    //import org.apache.excalibur.source.SourceResolver;
    import org.w3c.dom.Document;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;

    import com.ibm.as400.access.AS400;
    import com.ibm.as400.access.IFSJavaFile;
    import com.ibm.as400.vaccess.IFSFileSystemView;



    public class ParseTest {

    private File file;

    public ParseTest(File file)
    {
    this.file=file;

    DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
    //Logging with anonymus user,resolving ftp source
    //ftp://user:password@(protected):port/path
    /* SourceParameters params = new SourceParameters();
    params.setParameter("user", "anonymous");
    params.setParameter("password", "");
    Map map = new HashMap();
    map.put(SourceResolver.URI_PARAMETERS, params);
    targetSrc = resolver.resolveURI("http://xml.org/sax/features/validation",
    null,map);
    */
    // set attributes for validation (including xml schema)
    try {
    // factory.setAttribute(targetSrc, new Boolean(true));
    factory.setAttribute("http://xml.org/sax/features/validation", new
    Boolean(true));
    factory.setAttribute("http://apache.org/xml/features/validation/schema",
    new Boolean(true));

    factory.setValidating(true);
    }catch (IllegalArgumentException e) {
    // thrown if the underlying implementation doesn't recognize the
    attributes
    System.out.println("Underlying implementation doesn't recognize
    the attribute.");
    System.out.println("getXmlAlgorithmDocument():IllegalArgumentException
    " + e.getMessage()+ "\n");
    e.printStackTrace();
    //return null;
    }
    DocumentBuilder builder = null;
    Document doc = null;
    ErrorHandler errorHandler = new MyErrorHandler();




    try {
    // get an instance of a builder
    builder = factory.newDocumentBuilder();
    // Register the error handler
    builder.setErrorHandler(new MyErrorHandler());//If an application
    does not register an ErrorHandler, XML parsing errors will go
    unreported and bizarre behaviour may result.

    }
    catch (ParserConfigurationException e) {
    System.out.println("getXmlAlgorithmDocument():parserConfigurationException
    " + e.getMessage()+ "\n");
    e.printStackTrace();
    // return null;
    }

    try {
    // parse the algorithm file and get document
    doc = builder.parse(file);

    }
    catch (SAXParseException e) {
    System.out.println("\n** Parsing error" + ", line " +
    e.getLineNumber()
    + ", uri " + e.getSystemId());
    System.out.println("getXmlAlgorithmDocument(): SAXParseException "
    + e.getMessage()+ "\n");
    e.printStackTrace();
    // return null;
    }
    catch (SAXException e) {
    // parser throws SAXException ,If any parse errors occur
    System.out.println("getXmlAlgorithmDocument(): SAXException " +
    e.getMessage()+ "\n");
    e.printStackTrace();
    // return null;
    }
    catch (IOException e) {
    // parser throws IOException
    System.out.println("getXmlAlgorithmDocument(): IOException " +
    e.getMessage()+ "\n");
    e.printStackTrace();
    // return null;
    }
    catch (IllegalArgumentException e) {
    // parser throws IllegalArgumentException, If the file is null
    System.out.println("getXmlAlgorithmDocument():
    IllegalArgumentException " +
    e.getMessage()+ "\n");
    e.printStackTrace();
    // return null;
    }

    }


    public static void main(String[] args) throws IOException {


    // Work with /Dir/File.txt on the system wkdis3.
    AS400 system = new AS400("wkdis3");
    IFSJavaFile dir = new IFSJavaFile(system, "//wkdis3/ROOT/home/bwe/");
    String directory0 = dir.getParent();
    System.out.println ("Directory0: " + directory0);
    String directory4=dir.getCanonicalPath();
    System.out.println ("Canonicalpath-Directory4: " + directory4);
    // IFSJavaFile dir = new IFSJavaFile( "\\wkdis3\ROOT\home\bwe");
    JFileChooser chooser = new JFileChooser(dir, new
    IFSFileSystemView(system));
    Frame parent = new Frame();



    int returnVal = chooser.showOpenDialog(parent);

    if (returnVal == JFileChooser.APPROVE_OPTION) {

    IFSJavaFile chosenFile =
    (IFSJavaFile)(chooser.getSelectedFile());

    System.out.println("You selected the file named " +
    chosenFile.getName());
    String filename = chosenFile.getName();

    // XML files are here:("\\wkdis3\ROOT\home\bwe\AABB.XML");
    //IFSJavaFile file = new IFSJavaFile(system,directory4+filename);
    //File f=file;
    File f=new File(directory4+filename);
    ParseTest xIncludeTest = new ParseTest(f);
    }

    }

    }

    class MyErrorHandler implements ErrorHandler {

    /
    public void warning(SAXParseException exception) throws SAXException
    {
    System.out.println("**Parsing Warning**\n" +
    " Line: " +exception.getLineNumber() + "\n" +
    " URI: " +exception.getSystemId() + "\n" +
    " Message: " +exception.getMessage());
    throw new SAXException("Warning encountered");

    }



    public void error(SAXParseException exception) throws SAXException {
    System.out.println("**Parsing Error**\n" +
    " Line: " +exception.getLineNumber() + "\n" +
    " URI: " +exception.getSystemId() + "\n" +
    " Message: " +exception.getMessage());
    throw new SAXException("Error encountered");
    }

    public void fatalError(SAXParseException exception) throws
    SAXException {
    System.out.println("**Parsing Fatal Error**\n" +
    " Line: " +exception.getLineNumber() + "\n" +
    " URI: " +exception.getSystemId() + "\n" +
    " Message: " +exception.getMessage());
    throw new SAXException("Fatal Error encountered");
    }

    }
     
    Cigdem, Mar 16, 2005
    #1
    1. Advertising

  2. (Cigdem) writes:

    > I am trying to parse the XML files that the user selects(XML files are
    > on anoher OS400 system called "wkdis3"). But i am permenantly getting
    > that error:
    >
    > Directory0: \\wkdis3\ROOT\home
    > Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\
    > You selected the file named AAA.XML
    > getXmlAlgorithmDocument(): IOException Not logged in
    >
    > sun.net.ftp.FtpLoginException: Not logged in
    > at sun.net.ftp.FtpClient.readReply(Unknown Source)
    > at sun.net.ftp.FtpClient.issueCommand(Unknown Source)
    > at sun.net.ftp.FtpClient.login(Unknown Source)



    Appears to be an athentication problem, nothing to do with XML. Check
    that username and passwords are correctly sent to the server.

    -- Alain.

    P/S (perso): Merhaba Cigdem. Mes salutations de Strasbourg.
     
    Alain Ketterlin, Mar 16, 2005
    #2
    1. Advertising

  3. Bonjour :)

    I solved the problem, as you have told it was a problem of
    authentication.. Thanks again for the reply.

    PS: C'est un suprise très beaux de vous rencontrer dans l'Internet.
    J'habite maintenant en Allemagne, mais je manque beaucoup d'Istanbul.
    Maintenant je dois apprendre et parler toujours l'Allemand. En raison de
    cela, mon français est un peu plus mauvais maintenant. Je devine que
    vous travaillez à l'université de Strousburg en ce moment. Je vous
    souhaite des bonnes chances:)

    Cigdem Savaseri-Brackmann

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Cigdem Savaseri-Brackmann, Mar 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helen
    Replies:
    0
    Views:
    832
    Helen
    Mar 2, 2004
  2. Jasmin Wason
    Replies:
    0
    Views:
    497
    Jasmin Wason
    Aug 1, 2003
  3. bugbear
    Replies:
    0
    Views:
    1,043
    bugbear
    Aug 28, 2003
  4. Yona
    Replies:
    0
    Views:
    557
  5. Kevin Partin
    Replies:
    1
    Views:
    1,401
    Martin Honnen
    Feb 13, 2004
Loading...

Share This Page