Source Code Cross Referenced for DOMSrcExample.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:        import javax.xml.transform.dom.DOMSource;
043:
044:        public class DOMSrcExample {
045:            static DOMSource domSource;
046:
047:            public static void main(String[] args) {
048:                if (args.length != 1) {
049:                    System.err.println("Argument required: "
050:                            + "-Dxml-file=<filename>");
051:                    System.exit(1);
052:                }
053:
054:                DOMSrcExample dse = new DOMSrcExample();
055:
056:                DocumentBuilderFactory factory = DocumentBuilderFactory
057:                        .newInstance();
058:                factory.setNamespaceAware(true);
059:
060:                try {
061:                    DocumentBuilder builder = factory.newDocumentBuilder();
062:                    Document document = builder.parse(new File(args[0]));
063:                    domSource = new DOMSource(document);
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:                    System.out.println("\n** SAXException:");
082:
083:                    Exception x = sxe;
084:
085:                    if (sxe.getException() != null) {
086:                        x = sxe.getException();
087:                    }
088:
089:                    x.printStackTrace();
090:                } catch (ParserConfigurationException pce) {
091:                    // Parser with specified options can't be built
092:                    System.out.println("\n** ParserConfigurationException:");
093:                    pce.printStackTrace();
094:                } catch (IOException ioe) {
095:                    // I/O error
096:                    System.out.println("\n** IOException:");
097:                    ioe.printStackTrace();
098:                }
099:
100:                try {
101:                    // Create message factory
102:                    MessageFactory messageFactory = MessageFactory
103:                            .newInstance();
104:
105:                    // Create a message
106:                    SOAPMessage message = messageFactory.createMessage();
107:
108:                    // Get the SOAP part and set its content to domSource
109:                    SOAPPart soapPart = message.getSOAPPart();
110:                    soapPart.setContent(domSource);
111:
112:                    message.saveChanges();
113:
114:                    // Get contents using SAAJ APIs.
115:                    // Header is optional.
116:                    SOAPHeader header = message.getSOAPHeader();
117:
118:                    if (header != null) {
119:                        Iterator iter1 = header.getChildElements();
120:                        System.out.println("Header contents:");
121:                        dse.getContents(iter1, "");
122:                    }
123:
124:                    SOAPBody body = message.getSOAPBody();
125:                    Iterator iter2 = body.getChildElements();
126:                    System.out.println("Body contents:");
127:                    dse.getContents(iter2, "");
128:                } catch (Exception ex) {
129:                    System.out.println("\n** Exception:");
130:                    ex.printStackTrace();
131:                }
132:            }
133:
134:            // main
135:
136:            /*
137:             * Retrieves the contents of the elements recursively and
138:             * displays them.
139:             *
140:             * @param iterator        Iterator returned by getChildElements
141:             * @param indent        indentation to nest element display
142:             */
143:            public void getContents(Iterator iterator, String indent) {
144:                while (iterator.hasNext()) {
145:                    Node node = (Node) iterator.next();
146:                    SOAPElement element = null;
147:                    Text text = null;
148:
149:                    if (node instanceof  SOAPElement) {
150:                        element = (SOAPElement) node;
151:
152:                        Name name = element.getElementName();
153:                        System.out.println(indent + "Name is "
154:                                + name.getQualifiedName());
155:
156:                        Iterator attrs = element.getAllAttributes();
157:
158:                        while (attrs.hasNext()) {
159:                            Name attrName = (Name) attrs.next();
160:                            System.out.println(indent + " Attribute name is "
161:                                    + attrName.getQualifiedName());
162:                            System.out.println(indent + " Attribute value is "
163:                                    + element.getAttributeValue(attrName));
164:                        }
165:
166:                        Iterator iter2 = element.getChildElements();
167:                        getContents(iter2, indent + " ");
168:                    } else {
169:                        text = (Text) node;
170:
171:                        String content = text.getValue();
172:                        System.out.println(indent + "Content is: " + content);
173:                    }
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.