Source Code Cross Referenced for DOMExample.java in  » IDE-Netbeans » usersguide » domexample » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » usersguide » domexample 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S.
003:         * Government Rights - Commercial software.  Government users are subject
004:         * to the Sun Microsystems, Inc. standard license agreement and
005:         * applicable provisions of the FAR and its supplements.  Use is subject
006:         * to license terms.
007:         *
008:         * This distribution may include materials developed by third parties.
009:         * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010:         * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011:         * other countries.
012:         *
013:         * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014:         *
015:         * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016:         * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017:         * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018:         * en vigueur de la FAR (Federal Acquisition Regulations) et des
019:         * supplements a celles-ci.  Distribue par des licences qui en
020:         * restreignent l'utilisation.
021:         *
022:         * Cette distribution peut comprendre des composants developpes par des
023:         * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024:         * sont des marques de fabrique ou des marques deposees de Sun
025:         * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026:         */
027:        package domexample;
028:
029:        import javax.xml.parsers.DocumentBuilder;
030:        import javax.xml.parsers.DocumentBuilderFactory;
031:        import javax.xml.parsers.FactoryConfigurationError;
032:        import javax.xml.parsers.ParserConfigurationException;
033:        import javax.xml.soap.*;
034:        import org.xml.sax.SAXException;
035:        import org.xml.sax.SAXParseException;
036:        import java.io.File;
037:        import java.io.IOException;
038:        import java.util.*;
039:        import org.w3c.dom.Document;
040:        import org.w3c.dom.DOMException;
041:        import org.w3c.dom.NodeList;
042:
043:        public class DOMExample {
044:            static Document document;
045:
046:            public static void main(String[] args) {
047:                if (args.length != 1) {
048:                    System.err.println("Argument required: "
049:                            + "-Dxml-file=<filename>");
050:                    System.exit(1);
051:                }
052:
053:                DOMExample de = new DOMExample();
054:
055:                document = null;
056:
057:                DocumentBuilderFactory factory = DocumentBuilderFactory
058:                        .newInstance();
059:                factory.setNamespaceAware(true);
060:
061:                try {
062:                    DocumentBuilder builder = factory.newDocumentBuilder();
063:                    document = builder.parse(new File(args[0]));
064:                } catch (SAXParseException spe) {
065:                    // Error generated by the parser
066:                    System.out.println("\n** Parsing error" + ", line "
067:                            + spe.getLineNumber() + ", uri "
068:                            + spe.getSystemId());
069:                    System.out.println("   " + spe.getMessage());
070:
071:                    // Use the contained exception, if any
072:                    Exception x = spe;
073:
074:                    if (spe.getException() != null) {
075:                        x = spe.getException();
076:                    }
077:
078:                    x.printStackTrace();
079:                } catch (SAXException sxe) {
080:                    // Error generated during parsing)
081:                    Exception x = sxe;
082:
083:                    if (sxe.getException() != null) {
084:                        x = sxe.getException();
085:                    }
086:
087:                    x.printStackTrace();
088:                } catch (ParserConfigurationException pce) {
089:                    // Parser with specified options can't be built
090:                    pce.printStackTrace();
091:                } catch (IOException ioe) {
092:                    // I/O error
093:                    ioe.printStackTrace();
094:                }
095:
096:                try {
097:                    // Create message factory and SOAP factory
098:                    MessageFactory messageFactory = MessageFactory
099:                            .newInstance();
100:                    SOAPFactory soapFactory = SOAPFactory.newInstance();
101:
102:                    // Create a message
103:                    SOAPMessage message = messageFactory.createMessage();
104:
105:                    // Get the SOAP header from the message and remove it
106:                    SOAPHeader header = message.getSOAPHeader();
107:                    header.detachNode();
108:
109:                    // Get the SOAP body from the message
110:                    SOAPBody body = message.getSOAPBody();
111:
112:                    // Add the DOM document to the message body
113:                    SOAPBodyElement docElement = body.addDocument(document);
114:
115:                    message.saveChanges();
116:
117:                    // Get contents using SAAJ APIs
118:                    Iterator iter1 = body.getChildElements();
119:                    de.getContents(iter1, "");
120:                } catch (Exception ex) {
121:                    ex.printStackTrace();
122:                }
123:            }
124:
125:            // main
126:
127:            /*
128:             * Retrieves the contents of the elements recursively and
129:             * displays them.
130:             *
131:             * @param iterator        Iterator returned by getChildElements
132:             * @param indent        indentation to nest element display
133:             */
134:            public void getContents(Iterator iterator, String indent) {
135:                while (iterator.hasNext()) {
136:                    Node node = (Node) iterator.next();
137:                    SOAPElement element = null;
138:                    Text text = null;
139:
140:                    if (node instanceof  SOAPElement) {
141:                        element = (SOAPElement) node;
142:
143:                        Name name = element.getElementName();
144:                        System.out.println(indent + "Name is "
145:                                + name.getQualifiedName());
146:
147:                        Iterator attrs = element.getAllAttributes();
148:
149:                        while (attrs.hasNext()) {
150:                            Name attrName = (Name) attrs.next();
151:                            System.out.println(indent + " Attribute name is "
152:                                    + attrName.getQualifiedName());
153:                            System.out.println(indent + " Attribute value is "
154:                                    + element.getAttributeValue(attrName));
155:                        }
156:
157:                        Iterator iter2 = element.getChildElements();
158:                        getContents(iter2, indent + " ");
159:                    } else {
160:                        text = (Text) node;
161:
162:                        String content = text.getValue();
163:                        System.out.println(indent + "Content is: " + content);
164:                    }
165:                }
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.