Java tutorial
//package com.java2s; /* * Copyright (c) 2014 Ngewi Fet <ngewif@gmail.com> * Copyright (c) 2014 Yongxin Wang <fefe.wyx@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static final String ATTR_KEY_TYPE = "type"; public static final String TAG_SLOT_KEY = "slot:key"; public static final String TAG_SLOT_VALUE = "slot:value"; public static final String TAG_SLOT = "slot"; /** * Helper method for creating slot key-value pairs in the GnuCash XML structure. * <p>This method is only a helper for creating slots whose values are of string type</p> * @param doc {@link org.w3c.dom.Document} for creating nodes * @param key Slot key as string * @param value Slot value as String * @return Element node containing the key-value pair */ public static Element createSlot(Document doc, String key, String value, String valueType) { Element slotNode = doc.createElement(TAG_SLOT); Element slotKeyNode = doc.createElement(TAG_SLOT_KEY); slotKeyNode.appendChild(doc.createTextNode(key)); Element slotValueNode = doc.createElement(TAG_SLOT_VALUE); slotValueNode.setAttribute(ATTR_KEY_TYPE, valueType); slotValueNode.appendChild(doc.createTextNode(value)); slotNode.appendChild(slotKeyNode); slotNode.appendChild(slotValueNode); return slotNode; } }