Sponsored Content
Top Forums Shell Programming and Scripting Extract values from xml file script Post 303019535 by stomp on Sunday 1st of July 2018 03:11:30 PM
Old 07-01-2018
Hi,

I suggest to use an XML-Tool for parsing an XML-File. Look at the thread here for some tools:

Extract a value from an xml file

XPath ist name of the Search-Syntax, you can use to find values:

Some Examples:

Get the Projectname
Code:
xmllint --xpath "//ProjectName/text()" file.xml

Get all NameIDs
Code:
xmllint --xpath "//NameID/text()" file.xml

Get STX for a section NameID "MACLS"
Code:
xmllint --xpath "//*[NameID[text()='MACLS']]/STR_VAL/STX/text()"

That are a lot of xmllint calls. I myself would use a scripting language that has xml as library. But Bash with xmllint should be possible to albeit not so fast.
This User Gave Thanks to stomp For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script to extract data from XML file

Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>... (5 Replies)
Discussion started by: yajaykumar
5 Replies

2. Shell Programming and Scripting

Extract XML Element Values

I have a rather large file with XML-style content. Each line contains one full XML entry. For example: 1:<Message><DNIS>1234</DNIS><UCID>3456</UCID><TransferGroup>XYZXYZ</TransferGroup></Message> 2:<Message><DNIS>9999</DNIS><UCID>2584</UCID><TransferGroup>ABCABC</TransferGroup></Message>... (1 Reply)
Discussion started by: sharpi03
1 Replies

3. Shell Programming and Scripting

KSH Script to Get the <TAG Values> from an XML file

Hi All, I am new to Unix I need a KSH script to get the values from XML file to write to a temp file. Like the requirement is from the below TAG <MAPPING DESCRIPTION ="Test Mapping" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"> I need the MAPPING DESCRIPTION... (3 Replies)
Discussion started by: perlamohan
3 Replies

4. Shell Programming and Scripting

Perl script to extract 'ID' From XML File

File1.xml <?xml version.........> - <abcd:abcd_list version="1" www.john_uncle's_server.com" xmlns: - <device id="100"> <firmware>12.4(3d)</firmware> <location id="500">Sitting Room</location> </device> - <device id="101"> <firmware>12.4(3d)</firmware> <location id="501">Class... (1 Reply)
Discussion started by: sureshcisco
1 Replies

5. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

6. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

7. Shell Programming and Scripting

Passing values to an XML file from shell script

:wall: Hi, I have an XML file with 5 tags. I need to pass values to the XML file from a shell script that will replace values in 2 of the tags. I cannot hardcode the tag values in XML and use replace command in script as the values are likely to change. Please help !!!!!!!!!!! (2 Replies)
Discussion started by: Monalisaa
2 Replies

8. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

9. Shell Programming and Scripting

How to extract xml attribute values using awk inline.?

I am trying to extract specific XML attribute values for search pattern <factories.*baseQueueName' from resources.xml. my scripts works ok,, but to extract 3 values this code does echo $line three times, it could be 'n' times. How can I use awk to extract matching pattern values in-line or... (11 Replies)
Discussion started by: kchinnam
11 Replies
libxml(3)						     Library Functions Manual							 libxml(3)

NAME
libxml - library used to parse XML files DESCRIPTION
The libxml library is used to parse XML files. Its internal document repesentation is as close as possible to the DOM (Document Object Model) interface, an API for accessing XML or HTML structured documents. The libxml library also has a SAX-like interface, which is designed to be compatible with expat(1). NOTE: SAX, the Simple API for XML, is a standard interface for event-based XML parsing, developed collaboratively by the members of the XML-DEV mailing list, currently hosted by OASIS. The expat library is a XML 1.0 parser written in C, which aims to be fully conforming. It is currently not a validating XML pro- cessor. The libxml library now includes a nearly complete XPath implementation. The XPath (XML Path Language) is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer. The libxml library exports Push and Pull type parser interfaces for both XML and html. FILES
/depot/lib/libxml_2.0.0/libxml.a static library /depot/lib/libxml_2.0.0/libxml.so shared library /depot/package/libxml_2.0.0/bin/xmllint binary application for parsing XML files AUTHORS
Daniel Veillard (daniel@veillard.com). Red Hat Inc. Manual page by Ziying Sherwin (sherwin@nlm.nih.gov), Lister Hill National Center for Biomedical Communications, U.S. National Library of Medicine. SEE ALSO
xmllint(1), libxslt(3), libexslt(3), xsltproc(1) 12 April 2000 libxml(3)
All times are GMT -4. The time now is 03:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy