• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 91
  • Last Modified:

get resource values from xml

Please see the attached XML, there are multiple resources,

I want to be able to find the resource whose name is "jdbc/PegaRULES" and create a new xml file which has only that resource.

For example: newfile.xml should be like:

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
<Resource
			auth="Container"
			name="jdbc/PegaRULES"
			type="javax.sql.DataSource"
			maxActive="100"
			maxIdle="30"
			maxWait="10000"
			username="user1"
			password="password1!"
			driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
			url="jdbc:sqlserver://server1;databaseName=db1;SelectMethod=cursor;SendStringParametersAsUnicode=false"
		/>

<Environment name="prconfig/database/databases/PegaRULES/defaultSchema" value="rulesval1" type="java.lang.String" /> 
  <Environment name="prconfig/database/databases/PegaDATA/defaultSchema" value="dataval2" type="java.lang.String" />
<!--
		<Environment name="url/initialization/explicittempdir" value="D:/PegaTempDir" type="java.lang.String" />
-->
</Context>

Open in new window


Wondering if this can be done using bash.

Thanks
context_doesnotwork.xml
0
DevSupport
Asked:
DevSupport
2 Solutions
 
Duncan RoeSoftware DeveloperCommented:
Forget it. You have to use something more suitable, such as a SAX parser (available in python for instance). You might find this simplified interface helpful.
0
 
DevSupportAuthor Commented:
@Duncan Roe:
Thank You for you inputs. As you suggested I found a solution to my requirement using xidel XML parser.
This is what I did:
     
        urlarr=($(xidel tempcontext.xml -s -e //@url))
        namearr=($(xidel tempcontext.xml -s -e //@name))
        autharr=($(xidel tempcontext.xml -s -e //@auth))
        typearr=($(xidel tempcontext.xml -s -e //@type))
        driverclassnamearr=($(xidel tempcontext.xml -s -e //@driverClassName))

 newcount=0

and then :

    for s in {0..10}
        do
        if [ "${namearr[$newcount]}" = "jdbc/PegaRULES" ]
         then
        break
        fi
        newcount=$(expr $newcount + 1)
        done
        tdc=/Scripts/tempdriverclassname
        cp /dev/null /Scripts/tempdriverclassname
        ura=/Scripts/urlarrstring
        cp /dev/null /Scripts/urlarrstring
        if [ -f "$tdc" ]
         then
         echo "${driverclassnamearr[$newcount]}" > "$tdc"
         echo "${urlarr[$newcount]}" > "$ura"
etc
        fi

Open in new window

        and then create file using these values
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now