Hi, please help on this. I want extract values of xml file structure and print in determined way.
<ProjectName> --> only appears once
<StructList> --> is the top node
<Struct> node --> could be more than 1
NameID, STX, STY, PRX, PRY --> appears only 1 time within each <Struct> node
<PR_Ranges> node --> only appears once but inside this node could be more than 1 <RangesInfo>
I want to extract children (OD, ODF, ODRangeStart and ODRangeStop) from each <RangesInfo>
I want to print the values for each <Struct> node in a single line with this format
My input xml, current awk code and current output that is wrong is below
XPath ist name of the Search-Syntax, you can use to find values:
Some Examples:
Get the ProjectnameGet all NameIDsGet STX for a section NameID "MACLS"
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.
I suggest to use an XML-Tool for parsing an XML-File. Look at the thread here for some tools:
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.
Hi stomp, thanks for your answer and suggestion. I'll have in mind this xml tool, but for now I think I close to get the output desired with awk.
---------- Post updated at 11:05 PM ---------- Previous update was at 11:04 PM ----------
Quote:
Originally Posted by Chubler_XL
This appears to work OK for you sample input:
Hi Chubler_XL,
Thanks. It works, but trying with a real input xml it prints a kind of different output, this was mmy fault
since in order to make the sample input shorter I missed some nodes.
Below I present a more representative sample file.
- The nodes STR_VAL and PRO_VAL are the same structure, the issue is exist a parent node called <GROUP_Ranges> that contains
the children <XB_Ranges>, <PR_Ranges> and <KJ_Ranges>. Each one of this children have the same sub-children named OD, ODF, ODRange, etc.
The output desired remains the same, I only want to extract the sub-children of <PR_Ranges>, since my first sample file was less representative, your
current solution is printing the sub-children of <XB_Ranges> and sub-children of <KJ_Ranges>. In addition, the values of STX, STY, PRX, and PRY are not being
printed when input file is like this second sample file.
May be you can help me to fix this, how to print the same output as before but considering only values from PR_Ranges.
The input file 2 is:
The output for this input file 2 would be like this:
Thanks
A little confused with this. The <STR_VAL> block for the first output line appears after the <ODRange> block for the 2nd output line.
How do you match up STX-STY values in the XLM with their appropriate output lines?
Actually <STR_VAL> and <PRO_VAL> goes after <ValueRange>/<ODRange>. In first sample STR_VAL appears before for the same reason as explain that was a not too representative sample.
All the values related witn each <NameID>, STX-STY and each PRX-PRY are inside each <Struct> node. I donīt know if I answer your doubts.
Actually <STR_VAL> and <PRO_VAL> goes after <ValueRange>/<ODRange>. In first sample STR_VAL appears before for the same reason as explain that was a not too representative sample.
All the values related witn each <NameID>, STX-STY and each PRX-PRY are inside each <Struct> node. I donīt know if I answer your doubts.
No. You have not answered our doubts. You gave us sample input in post #1 and you showed us the output you wanted from that input. And, you were given code that produced that output from that input and then you changed your requirements.
In post 4 you gave us new sample input and you said "The output for this input file 2 would be like this:" and you showed us some output. But with that wording, I don't know if you are saying that that is the output you get from some code that has been suggested (but not what you want), that it is the output you get from some other code that you're using (but not what you want), or if it is the output you want from that new input.
Furthermore, you haven't clearly specified whether the original input you provided in post #1 was valid input that did not include data that was needed to trigger special cases that were missing from your original algorithm (and the code you want should still provide the output you said you want from that input in post #1) or if the input you provided in post #1 was not valid input and everything you said about the output you wanted to be produced from that input should be ignored.
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)
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)
: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)
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)
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)
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)
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)
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)