Solved

xml xmlns namespace and xsi_type extractions from xml using bash

Posted on 2013-05-14
4
398 Views
Last Modified: 2013-05-30
Greetings.
I need to know how to pull the values from XML header information:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://www.accessdata.fda.gov/spl/schema/spl.xsd">

Open in new window


In addition, in several areas I have tags with xsi_type: attributes in it.  They do not show up in XPATH locations.  (ie. <tag xsi_type="CE" ... />

I am obligated to pull the xmlns, xmlns:xsi, xsi:schemaLocation and the specific tag (assuming I know the xpath to the tag) into a bash variable to do something with it.  Is this possible?

Thanks.
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://www.accessdata.fda.gov/spl/schema/spl.xsd">
   

Open in new window

0
Comment
Question by:Evan Cutler
  • 2
4 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 39167652
which value in which header?
can you please give an example what to extract from where
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39168120
I need all of them.
I need to put them into a variable in BASH so I can put it somewhere.

Thanks.
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 39168719
xsi:type (it should be colon and not underscore) should show up in the XPath (given the right expression).  Are you sure it does not?

For parsing XML, you really want a true parser of some sort.  Since you reference XPath, I'm assuming you have access to one.  Otherwise, I would write a small script in Perl (or your language of choice) to extract the pieces you need.

That said, you can extract XML using regexes but it's tricky.
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 39209504
Thanks for helping.  I am still looking for answers...but I appreciate the attempt.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now