Commit 94bd47ba by Owen Ryan Ang

Merge branch 'feature-doctype-update' into 'development-mobile'

Feature doctype update See merge request !76
parents 52c263e4 f7d141dc
...@@ -167,7 +167,7 @@ export class BPO { ...@@ -167,7 +167,7 @@ export class BPO {
async getMobileFieldData() { async getMobileFieldData() {
let elementId = sessionStorage.getItem("element_id"); let elementId = sessionStorage.getItem("element_id");
let xmlData = { let xmlData = {
"outputDir": sessionStorage.getItem("element_file_loc") + "/" + (ENCODING_PASS == "PASS1" ? elementId + ".DTA" : elementId + ".DTB") "outputDir": sessionStorage.getItem("element_file_loc") + "/" + elementId + ".DFC"
} }
let response = await fetch(urlGetMobileFields, { let response = await fetch(urlGetMobileFields, {
......
//Data Input Field Config //Data Input Field Config
export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/schema_sqa.json"; export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/Navotas 2.json";
// export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/HR Speed Test schema.json";
//DBLookup Webservice URL //DBLookup Webservice URL
export var DB_URL = "http://localhost:8080/WebGde/svc/gfs-rest/db-lookup" export var DB_URL = "http://localhost:8080/WebGde/svc/gfs-rest/db-lookup"
\ No newline at end of file
...@@ -15,6 +15,7 @@ let newOption; ...@@ -15,6 +15,7 @@ let newOption;
export let schema; export let schema;
export async function generateFields(inputSchema, containerId) { export async function generateFields(inputSchema, containerId) {
window.populateFields = populateFields;
schema = inputSchema; schema = inputSchema;
let divContainer = document.getElementById(containerId); let divContainer = document.getElementById(containerId);
...@@ -197,10 +198,8 @@ export async function generateFields(inputSchema, containerId) { ...@@ -197,10 +198,8 @@ export async function generateFields(inputSchema, containerId) {
$(document).ready(function() { $(document).ready(function() {
$('form:first *:input[type!=hidden]:first').focus(); // Run code $('form:first *:input[type!=hidden]:first').focus(); // Run code
}); });
}
}
...@@ -242,6 +241,32 @@ const noValidation = (key) => { ...@@ -242,6 +241,32 @@ const noValidation = (key) => {
* @returns * @returns
* created input field element * created input field element
*/ */
const inputHidden = (key, validation) => {
try {
const input = document.createElement('textarea');
input.setAttribute('rows', 5);
input.setAttribute('id', key);
input.setAttribute('name', key);
input.setAttribute('cols', 30);
input.setAttribute('autocomplete', 'off');
input.setAttribute('inputMode', validation.collection === 'email' ? 'email' : 'text');
input.addEventListener('focusout', handleInput);
return input;
} catch (err) {
throw err;
}
}
/**
*
* @param {*} key
* will serve as id of input field
* @param {*} validation
* validation of field from schema
* @returns
* created input field element
*/
const inputString = (key, validation) => { const inputString = (key, validation) => {
try { try {
const { const {
...@@ -1829,21 +1854,37 @@ const deconstruct = async (section, container, classAttribute) => { ...@@ -1829,21 +1854,37 @@ const deconstruct = async (section, container, classAttribute) => {
fieldLabel, hidden fieldLabel, hidden
} = section[key] } = section[key]
// Create hidden input for fields with hidden="y" const validation = getValidation(key, schema)
// if (hidden && hidden.toLowerCase() === "y") {
// const hiddenInput = document.createElement('input');
// hiddenInput.setAttribute('type', 'hidden');
// hiddenInput.setAttribute('name', key);
// hiddenInput.setAttribute('value', ''); // Set the value as needed
// // Append the hidden input to the container
// container.appendChild(hiddenInput); if (hidden) {
const hiddenField = document.createElement('div') // will contain input field and label
hiddenField.setAttribute('class', 'fieldContainer ' + classAttribute)
container.appendChild(hiddenField)
// // Skip creating other visible input elements for hidden fields const labelContainer = document.createElement('div') // name beside input field
// continue; labelContainer.setAttribute('class', 'labelContainer ' + classAttribute)
// } hiddenField.appendChild(labelContainer)
const validation = getValidation(key, schema) const label = document.createElement('label')
label.textContent = fieldLabel ? fieldLabel : `Missing label`
label.style.color = fieldLabel ? '#000000' : '#ff3333'
labelContainer.appendChild(label)
const inputContainer = document.createElement('div') // input field
inputContainer.setAttribute('class', 'inputContainer ' + classAttribute)
hiddenField.appendChild(inputContainer)
// default hiddeninputs to String
const hiddenInput = inputHidden(key, schema);
hiddenInput.setAttribute('class', classAttribute)
inputContainer.appendChild(hiddenInput);
hiddenField.style.display = 'none'; // Hide the input
hiddenField.classList.add('hidden'); // Add 'hidden' class
continue;
}
const newField = document.createElement('div') // will contain input field and label const newField = document.createElement('div') // will contain input field and label
newField.setAttribute('class', 'fieldContainer ' + classAttribute) newField.setAttribute('class', 'fieldContainer ' + classAttribute)
...@@ -1924,10 +1965,6 @@ const deconstruct = async (section, container, classAttribute) => { ...@@ -1924,10 +1965,6 @@ const deconstruct = async (section, container, classAttribute) => {
} }
input.setAttribute('class', classAttribute) input.setAttribute('class', classAttribute)
inputContainer.appendChild(input) inputContainer.appendChild(input)
if (hidden && hidden.toLowerCase() === 'y') {
newField.style.display = 'none'; // Hide the input
newField.classList.add('hidden'); // Add 'hidden' class
}
} }
//keys na drop down //keys na drop down
...@@ -2226,10 +2263,15 @@ export async function populateFields() { ...@@ -2226,10 +2263,15 @@ export async function populateFields() {
for (let key of Object.keys(schema[doctype][section])) { for (let key of Object.keys(schema[doctype][section])) {
if (schema[doctype][section][key].aka == "field" + k) { if (schema[doctype][section][key].aka == "field" + k) {
//console.log("key = " + key); console.log("key = " + key + +", value ="+v);
//console.log("validation: " + schema[doctype][section][key].validation.collection); //console.log("validation: " + schema[doctype][section][key].validation.collection);
fields["field" + k] = v; fields["field" + k] = v;
if (schema[doctype][section][key].hidden){
document.getElementById(key).value = v;
continue;
}
if(schema[doctype][section][key].validation.collection === 'radiolist'){ if(schema[doctype][section][key].validation.collection === 'radiolist'){
//retrieve the radio button value from the XML //retrieve the radio button value from the XML
......
...@@ -22,6 +22,10 @@ export const validateInput = (fieldID, value) => { ...@@ -22,6 +22,10 @@ export const validateInput = (fieldID, value) => {
if(!validation) return { valid: false, error: [`FieldName: '${fieldID}' not in schema`] } if(!validation) return { valid: false, error: [`FieldName: '${fieldID}' not in schema`] }
// Skip validation for hidden fields
if (isFieldHidden(fieldID)){
return { valid: true };
}
switch(validation.collection) { switch(validation.collection) {
case 'email': case 'email':
return validateEmail(validation, value) return validateEmail(validation, value)
...@@ -429,4 +433,15 @@ export const checkValidValues = (fieldID, value) => { ...@@ -429,4 +433,15 @@ export const checkValidValues = (fieldID, value) => {
} catch(err) { } catch(err) {
return { isValidValue: false, errMsg: [err]} return { isValidValue: false, errMsg: [err]}
} }
} }
\ No newline at end of file
function isFieldHidden(key) {
for (const docType in schema) {
for (const section in schema[docType]) {
if (schema[docType][section][key] && schema[docType][section][key].hidden) {
return true;
}
}
}
return false;
}
\ No newline at end of file
...@@ -15,10 +15,15 @@ export async function WriteForm(e,metrics,doctype,section) { ...@@ -15,10 +15,15 @@ export async function WriteForm(e,metrics,doctype,section) {
// localStorage.setItem("submit", "1"); // localStorage.setItem("submit", "1");
let fields = {}; let fields = {};
for (var i=0;i<Nodes.length;i++) { for (var i=0;i<Nodes.length;i++) {
if (Nodes[i].style.display === 'none' && !Nodes[i].classList.contains('hidden')) continue if (Nodes[i].style.display === 'none' && !Nodes[i].classList.contains('hidden')) continue
let fid = Nodes[i].id; let fid = Nodes[i].id;
if (fid == 'DocType' || fid == 'Section' || fid == '' || fid == "submitButton") continue // Add doctype as field1
if (fid === 'DocType') {
fields['1'] = Nodes[i].value;
continue;
}
if (fid == 'Section' || fid == '' || fid == "submitButton") continue
// Skip the textbox in checklist and radiolist // Skip the textbox in checklist and radiolist
if (Nodes[i].classList.contains('radioOther') || Nodes[i].classList.contains('checkboxOther')) continue; if (Nodes[i].classList.contains('radioOther') || Nodes[i].classList.contains('checkboxOther')) continue;
// Skip elements of type "button", "submit", and files // Skip elements of type "button", "submit", and files
...@@ -73,8 +78,11 @@ export async function WriteForm(e,metrics,doctype,section) { ...@@ -73,8 +78,11 @@ export async function WriteForm(e,metrics,doctype,section) {
} }
fields[Object.keys(lookup[fid]).includes('aka') ? lookup[fid].aka.replace("field", "") : fid] = Nodes[i].value; fields[Object.keys(lookup[fid]).includes('aka') ? lookup[fid].aka.replace("field", "") : fid] = Nodes[i].value;
} }
let fieldOrder = extractAkaValues(schema, doctype, section);
console.log(fieldOrder);
let response = await createOutputXml(fields, myArray, doctype, section); let response = await createOutputXml(fields, myArray, doctype, section, fieldOrder);
return response; return response;
} }
catch(Err) { catch(Err) {
...@@ -83,17 +91,36 @@ export async function WriteForm(e,metrics,doctype,section) { ...@@ -83,17 +91,36 @@ export async function WriteForm(e,metrics,doctype,section) {
return false; return false;
} }
async function createOutputXml(fields, metrics, doctype, section) { function extractAkaValues(json, doctype, section) {
const akaValues = [];
function recursiveExtract(obj) {
for (const key in obj) {
if (typeof obj[key] === 'object') {
recursiveExtract(obj[key]);
} else if (key === 'aka') {
akaValues.push(obj[key].replace('field', ''));
}
}
}
recursiveExtract(json[doctype][section]);
return akaValues.join('|');
}
async function createOutputXml(fields, metrics, doctype, section, fieldOrder) {
let response = null; let response = null;
if (IS_RETRIEVE_FROM_BPO == "Y") { if (IS_RETRIEVE_FROM_BPO == "Y") {
response = await createBPOXML(fields, metrics, doctype, section); response = await createBPOXML(fields, metrics, doctype, section, fieldOrder);
} else{ } else{
response = await createNonBPOXML(fields, metrics, doctype, section); response = await createNonBPOXML(fields, metrics, doctype, section, fieldOrder);
} }
return response; return response;
} }
async function createNonBPOXML(fields, metrics, doctype, section){ async function createNonBPOXML(fields, metrics, doctype, section, fieldOrder){
console.log(fields);
let fileExt = ""; let fileExt = "";
switch(ENCODING_PASS){ switch(ENCODING_PASS){
case "PASS1": case "PASS1":
...@@ -137,7 +164,8 @@ async function createNonBPOXML(fields, metrics, doctype, section){ ...@@ -137,7 +164,8 @@ async function createNonBPOXML(fields, metrics, doctype, section){
"fields": fields, "fields": fields,
"outputDir": TEMPORARY_FOLDER + "/" + fileNameOnly + "/" + fileName, "outputDir": TEMPORARY_FOLDER + "/" + fileNameOnly + "/" + fileName,
"doctype": doctype, "doctype": doctype,
"section": section "section": section,
"fieldOrder" : fieldOrder
} }
let response = await fetch(urlWriteXml, { let response = await fetch(urlWriteXml, {
...@@ -151,7 +179,7 @@ async function createNonBPOXML(fields, metrics, doctype, section){ ...@@ -151,7 +179,7 @@ async function createNonBPOXML(fields, metrics, doctype, section){
return response; return response;
} }
async function createBPOXML(fields, metrics, doctype, section){ async function createBPOXML(fields, metrics, doctype, section, fieldOrder){
let elementId = sessionStorage.getItem("element_id"); let elementId = sessionStorage.getItem("element_id");
let filePaths = JSON.parse(sessionStorage.getItem("dir_files")); let filePaths = JSON.parse(sessionStorage.getItem("dir_files"));
...@@ -174,9 +202,10 @@ async function createBPOXML(fields, metrics, doctype, section){ ...@@ -174,9 +202,10 @@ async function createBPOXML(fields, metrics, doctype, section){
"subRecordNo": "1", "subRecordNo": "1",
"eor": "N", "eor": "N",
"fields": fields, "fields": fields,
"outputDir": sessionStorage.getItem("element_file_loc") + "/" + (ENCODING_PASS == "PASS1" ? elementId + ".DTA" : elementId + ".DTB"), "outputDir": sessionStorage.getItem("element_file_loc") + "/" + elementId + ".DVR",
"doctype": doctype, "doctype": doctype,
"section": section "section": section,
"fieldOrder" : fieldOrder
} }
let response = await fetch(urlWriteXml, { let response = await fetch(urlWriteXml, {
......
...@@ -21,7 +21,7 @@ export const IS_RETRIEVE_FROM_GFS = "N" ...@@ -21,7 +21,7 @@ export const IS_RETRIEVE_FROM_GFS = "N"
export const INVALID_KEYS = "F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,PrintScreen,ScrollLock,Pause,PageUp,PageDown,Insert,Delete,Control" export const INVALID_KEYS = "F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,PrintScreen,ScrollLock,Pause,PageUp,PageDown,Insert,Delete,Control"
//BPO CONFIG //BPO CONFIG
export const IS_RETRIEVE_FROM_BPO = "Y" export const IS_RETRIEVE_FROM_BPO = "N"
// export const BPO_URL = "http://35.171.20.94:8080/bpo-sqa/" // export const BPO_URL = "http://35.171.20.94:8080/bpo-sqa/"
// export const CURRENT_NODE = "Web GDE" // export const CURRENT_NODE = "Web GDE"
export let BPO_URL = DOMAIN + "bpo/"; export let BPO_URL = DOMAIN + "bpo/";
...@@ -30,7 +30,7 @@ export let CURRENT_NODE = "" ...@@ -30,7 +30,7 @@ export let CURRENT_NODE = ""
export const ENCODING_PASS = "PASS1" export const ENCODING_PASS = "PASS1"
export const NEXT_NODE = "Complete" export const NEXT_NODE = "Complete"
export const EXCEPTION_NODE = "Exception" export const EXCEPTION_NODE = "Exception"
export const SHOW_ELEMENT_LIST_VIEWER = "Y" export const SHOW_ELEMENT_LIST_VIEWER = "N"
export const ADD_NEW_OPTION = "N" export const ADD_NEW_OPTION = "N"
export const DISPLAYED_DETAILS = "Address" //pipe-delimited export const DISPLAYED_DETAILS = "Address" //pipe-delimited
......
...@@ -24,4 +24,8 @@ public class Field { ...@@ -24,4 +24,8 @@ public class Field {
this.no = no; this.no = no;
this.value = value; this.value = value;
} }
public String getNo() {
return this.no;
}
} }
...@@ -36,4 +36,8 @@ public class Record { ...@@ -36,4 +36,8 @@ public class Record {
this.section = xml.getSection(); this.section = xml.getSection();
this.subRecord = new SubRecord(xml); this.subRecord = new SubRecord(xml);
} }
public SubRecord getSubRecord() {
return this.subRecord;
}
} }
package com.svi.webgde.restservice.object; package com.svi.webgde.restservice.object;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.svi.webgde.restservice.utils.XMLUtil; import com.svi.webgde.restservice.utils.XMLUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
...@@ -31,4 +33,46 @@ public class SubRecord { ...@@ -31,4 +33,46 @@ public class SubRecord {
this.eor = xml.getEor(); this.eor = xml.getEor();
this.fields = XMLUtil.generateFields(xml); this.fields = XMLUtil.generateFields(xml);
} }
/**
* Arrange the contents of the fields list based on the order specified in the pipe-delimited string.
*
* @param orderPipeDelimited Pipe-delimited string specifying the order.
*/
public void arrangeFields(String orderPipeDelimited) {
List<Field> sortedFields = fields.stream()
.sorted((f1, f2) -> {
if ("1".equals(f1.getNo())) {
return -1; // f1 comes before f2
} else if ("1".equals(f2.getNo())) {
return 1; // f2 comes before f1
} else {
return Integer.compare(getOrder(f1.getNo(), orderPipeDelimited),
getOrder(f2.getNo(), orderPipeDelimited));
}
})
.collect(Collectors.toList());
// Update the fields list with the sorted order
fields.clear();
fields.addAll(sortedFields);
}
/**
* Helper method to get the order of a field based on the pipe-delimited string.
*
* @param fieldNo The field number to get the order for.
* @param orderPipeDelimited The pipe-delimited string specifying the order.
* @return The order of the field.
*/
private int getOrder(String fieldNo, String orderPipeDelimited) {
String[] orderArray = orderPipeDelimited.split("\\|");
for (int i = 0; i < orderArray.length; i++) {
if (orderArray[i].equals(fieldNo)) {
return i;
}
}
// Default to a high value if not found (end of the list)
return orderArray.length;
}
} }
package com.svi.webgde.restservice.object; package com.svi.webgde.restservice.object;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class XMLContents { public class XMLContents {
...@@ -21,10 +22,19 @@ public class XMLContents { ...@@ -21,10 +22,19 @@ public class XMLContents {
private String imageName; private String imageName;
private int subRecordNo; private int subRecordNo;
private String eor; private String eor;
private Map<String, String> fields; private Map<String, String> fields = new LinkedHashMap<>();;
private String outputDir; private String outputDir;
private String doctype; private String doctype;
private String section; private String section;
private String fieldOrder;
public String getFieldOrder() {
return fieldOrder;
}
public void setFieldOrder(String fieldOrder) {
this.fieldOrder = fieldOrder;
}
public String getProjCode() { public String getProjCode() {
return projCode; return projCode;
...@@ -193,4 +203,5 @@ public class XMLContents { ...@@ -193,4 +203,5 @@ public class XMLContents {
public void setSection(String section) { public void setSection(String section) {
this.section = section; this.section = section;
} }
} }
...@@ -20,7 +20,10 @@ import javax.xml.transform.TransformerException; ...@@ -20,7 +20,10 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
...@@ -67,29 +70,41 @@ public class XMLUtil { ...@@ -67,29 +70,41 @@ public class XMLUtil {
*/ */
public static String generateXML(XMLContents xml) throws TransformerException, ParserConfigurationException, public static String generateXML(XMLContents xml) throws TransformerException, ParserConfigurationException,
SAXException, IOException, XPathExpressionException { SAXException, IOException, XPathExpressionException {
XStream xs = new XStream(new DomDriver("ISO-8859-1", new XmlFriendlyNameCoder("_-", "_"))); XStream xs = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("_-", "_")));
xs.alias(xml.getProjCode(), OutputXML.class); xs.alias(xml.getProjCode(), OutputXML.class);
xs.processAnnotations(Record.class); xs.processAnnotations(Record.class);
Header header = new Header(xml); Header header = new Header(xml);
Record record = new Record(xml); Record record = new Record(xml);
record.getSubRecord().arrangeFields(xml.getFieldOrder());
OutputXML output = new OutputXML(header, record); OutputXML output = new OutputXML(header, record);
// SAXParserFactory spf = SAXParserFactory.newInstance(); // SAXParserFactory spf = SAXParserFactory.newInstance();
// SAXParser sp = spf.newSAXParser(); // SAXParser sp = spf.newSAXParser();
// Source source = new SAXSource(sp.getXMLReader(), // Source source = new SAXSource(sp.getXMLReader(),
// new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " ")))); // new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[
// ](?![^\\W_])", " "))));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( Document document = builder.parse(
new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " ")))); new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " "))));
// Generate list of all empty Nodes, them remove them
XPath xp = XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList) xp.evaluate("//text()[normalize-space(.)='']", document, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength(); ++i) { // note the position of the '++'
Node node = nl.item(i);
node.getParentNode().removeChild(node);
}
DOMSource source = new DOMSource(document); DOMSource source = new DOMSource(document);
TransformerFactory transformerFactory = TransformerFactory.newInstance(); TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(); Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
...@@ -334,31 +349,41 @@ public class XMLUtil { ...@@ -334,31 +349,41 @@ public class XMLUtil {
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xml.getOutputDir()); Document document = builder.parse(xml.getOutputDir());
Node imagename = document.getElementsByTagName("imagename").item(0); Element record = (Element) document.getElementsByTagName("record").item(0);
Node xmlSubRecord = imagename.getParentNode().getLastChild().getPreviousSibling(); if (record != null) {
Map<String, String> fields = new HashMap<>(); records.put("DocType", getElementTextByTagName(record, "doctype"));
records.put("Section", getElementTextByTagName(record, "section"));
records.put("DocType", imagename.getParentNode().getFirstChild().getNextSibling().getNextSibling()
.getNextSibling().getTextContent()); Map<String, String> fields = new HashMap<>();
records.put("Section", imagename.getParentNode().getFirstChild().getNextSibling().getNextSibling() records.put("fields", fields);
.getNextSibling().getNextSibling().getNextSibling().getTextContent());
records.put("fields", fields); Element subRecord = (Element) record.getElementsByTagName("sub-record").item(0);
if (subRecord != null) {
for (int i = 0; i < xmlSubRecord.getChildNodes().getLength(); i++) { NodeList fieldList = subRecord.getElementsByTagName("field");
if (xmlSubRecord.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE) { for (int j = 0; j < fieldList.getLength(); j++) {
for (int j = 0; j < xmlSubRecord.getChildNodes().item(i).getChildNodes().getLength(); j++) { Element field = (Element) fieldList.item(j);
if (xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j) String noAttributeValue = field.getAttribute("no");
.getNodeType() == Node.ELEMENT_NODE) { String textContentValue = field.getElementsByTagName("value").item(0).getTextContent();
fields.put(
xmlSubRecord.getChildNodes().item(i).getAttributes().getNamedItem("no").getNodeValue(), if ("1".equals(noAttributeValue)) {
xmlSubRecord.getChildNodes().item(i).getChildNodes().item(j).getTextContent()); // Replace the value of "DocType" with the text content
records.put("fields", fields); records.put("DocType", textContentValue);
} }
}
} fields.put(noAttributeValue, textContentValue);
} }
}
}
return records;
}
return records; private static String getElementTextByTagName(Element parentElement, String tagName) {
NodeList elements = parentElement.getElementsByTagName(tagName);
if (elements.getLength() > 0) {
return elements.item(0).getTextContent();
}
return null; // or an appropriate default value
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment