1- // reading xml values is resilient to errors but you can uncomment the next line for debugging if attributes are missing
21export function getXmlAttributeValue ( xml : any , name : string ) : string | undefined {
32 try {
43 return xml . $ [ name ] ;
54 } catch ( err ) {
5+ // reading xml values is resilient to errors but you can uncomment the next line for debugging if attributes are missing
66 // console.error(`Unable to get xml attribute value "${name}". ${err}`);
77 }
88 }
@@ -14,7 +14,6 @@ export function getXmlElementAttributeValue(xml: any, elementName: string, attri
1414 }
1515}
1616
17- // reading xml values is resilient to errors but you can uncomment the next line for debugging if elements are missing
1817export function getXmlElementValue ( xml : any , name : string ) : string | undefined {
1918 try {
2019 const element = xml [ name ] ;
@@ -23,29 +22,15 @@ export function getXmlElementValue(xml: any, name: string): string | undefined {
2322 return element [ 0 ] ;
2423 }
2524 } catch ( err ) {
26- // console.error(`Unable to get xml element value "${name}". ${err}`);
25+ // reading xml values is resilient to errors but you can uncomment the next line for debugging if elements are missing
26+ // console.error(`Unable to get xml element value "${name}". ${err}`);
2727 }
2828 }
2929
3030export function setXmlElementValue ( xml : any , elementName : string , input : any ) {
31- const element = getXmlElementValue ( xml , elementName ) ;
32-
33- if ( element ) {
34- try {
35- xml [ elementName ] = input ;
36- } catch ( err ) {
37- console . error ( `Unable to write value to xml element: ${ err } ` ) ;
38- }
39- return xml ;
40- }
31+ xml [ elementName ] = input ;
4132}
4233
4334export function setElementAttributeValue ( xml : any , elementName : string , input : string | undefined , attributeName : string = "DefaultValue" ) {
44- const element = getXmlElementValue ( xml , elementName ) ;
45-
46- if ( element ) {
47- try {
48- xml [ elementName ] [ 0 ] . $ [ attributeName ] = input ;
49- } catch ( err ) { console . error ( `Unable to write value to xml attribute: ${ err } ` ) ; }
50- }
35+ xml [ elementName ] [ 0 ] . $ [ attributeName ] = input ;
5136}
0 commit comments