01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.util;
20:
21: import org.w3c.dom.Attr;
22: import org.w3c.dom.Document;
23: import org.w3c.dom.Element;
24: import org.w3c.dom.Node;
25:
26: import javax.xml.parsers.DocumentBuilderFactory;
27: import javax.xml.parsers.ParserConfigurationException;
28:
29: public class XSLTUtils {
30:
31: public static Document getDocument()
32: throws ParserConfigurationException {
33: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
34: .newInstance();
35: documentBuilderFactory.setNamespaceAware(true);
36: return documentBuilderFactory.newDocumentBuilder()
37: .newDocument();
38: }
39:
40: /**
41: * Utility method to add an attribute to a given element
42: *
43: * @param document
44: * @param AttribName
45: * @param attribValue
46: * @param element
47: */
48: public static void addAttribute(Document document,
49: String AttribName, String attribValue, Element element) {
50: Attr attribute = document.createAttribute(AttribName);
51: attribute.setValue(attribValue);
52: element.setAttributeNode(attribute);
53: }
54:
55: public static Element getElement(Document document,
56: String elementName) {
57: return document.createElement(elementName);
58:
59: }
60:
61: /**
62: * Utility method to add an attribute to a given element
63: *
64: * @param document
65: * @param elementName
66: * @param parentNode
67: */
68: public static Element addChildElement(Document document,
69: String elementName, Node parentNode) {
70: Element elt = document.createElement(elementName);
71: parentNode.appendChild(elt);
72: return elt;
73: }
74:
75: }
|