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
DevSupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.