Find if XML element has a matching required element
I want to check if every <Part> element has corresponding <Description> in this sample XML.
Code:
....<Lot Of XML>
<Inv lineNumber="2">
<Item>
<Part>xxxxxx</Part>
</Item>
<Description>aaaaa bbbbbbbbbbbb</Description>
</Inv>
....<Lot Of XML>
<Inv lineNumber="2">
<Item>
<Part>xxxxxx</Part>
</Item>
</Inv>
....<Lot Of XML>
<Inv lineNumber="2">
<Item>
<Part>xxxxxx</Part>
</Item>
<Description>aaaaa bbbbbbbbbbbb</Description>
</Inv>
....<Lot Of XML>
This example should fail, since second <Part> does not have corresponding <Description>. I can count total <part> elements and total <Description> elements but does not feel that its the right way to do it.
Parsing using xml tools is not an option.
Last edited by kchinnam; 01-08-2012 at 11:26 PM..
Reason: data correction
Hi All,
I am looking for a awk/shell which can find an element named REFERENCE in a XML file and check whether it is empty or not.
If there is no value in the REFERENCE element then correspondingly move the file to some other folder.
The Unix server is AIX version 4.
Any inputs... (9 Replies)
Hi,
I have defined an array which holds a couple of elements which are nothing but files names. I want to find the files in a directory for the matching file name(array elements) with less than 1 day old.
When I am trying to execute the code (as below), it gives an error.
Your help in this... (1 Reply)
Hi All
Can someone please help me with this awk to search an element in a XML file with a particular value and then change the root element.
Thanks & Regards
Karan (9 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)
Hi, I would need to read an xml element from an xml file to a local variable. Please could you help me with a shell script to get so? Considering that I have a file called file.xml like below:
<header>
<description>This is the description</description>
<content>This is the... (2 Replies)
Any help to extract the root element from an XML file will be appreciated.
Example: test.xml
<?xml version="1.0" encoding="utf-8" ?>
<TestXMLMessage>
<TestRec>
<ID>1000</ID>
</TestRec>
</TestXMLMessage>
Wanted to extract the TestXMLMessage.
Regards,
Chari (6 Replies)
Hi,
I'm trying to write a script for some xml file handling, but I'm not getting too far with it.
I've got the following xml content
<?xml version="1.0" encoding="UTF-8"?>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<Operation name="OPER1">
<Action name="ACTION1">... (2 Replies)
Hi All
I have a problem that I am not able to resolve.
Briefly, I have a file like this:
ID_1 10
ID_2 15
ID_3 32
ID_4 45
ID_5 66
ID_6 79
ID_7 88This file is numerically ordered for the 2th column.
And another file containing a list of IDs(just one in this example)
ID_4What I... (7 Replies)
XML::Parser::Lite::Tree(3pm) User Contributed Perl Documentation XML::Parser::Lite::Tree(3pm)NAME
XML::Parser::Lite::Tree - Lightweight XML tree builder
SYNOPSIS
use XML::Parser::Lite::Tree;
my $tree_parser = XML::Parser::Lite::Tree::instance();
my $tree = $tree_parser->parse($xml_data);
OR
my $tree = XML::Parser::Lite::Tree::instance()->parse($xml_data);
DESCRIPTION
This is a singleton class for parsing XML into a tree structure. How does this differ from other XML tree generators? By using
XML::Parser::Lite, which is a pure perl XML parser. Using this module you can tree-ify simple XML without having to compile any C.
For example, the following XML:
<foo woo="yay"><bar a="b" c="d" />hoopla</foo>
Parses into the following tree:
'children' => [
{
'children' => [
{
'children' => [],
'attributes' => {
'a' => 'b',
'c' => 'd'
},
'type' => 'element',
'name' => 'bar'
},
{
'content' => 'hoopla',
'type' => 'text'
}
],
'attributes' => {
'woo' => 'yay'
},
'type' => 'element',
'name' => 'foo'
}
],
'type' => 'root'
};
Each node contains a "type" key, one of "root", "element" and "text". "root" is the document root, and only contains an array ref
"children". "element" represents a normal tag, and contains an array ref "children", a hash ref "attributes" and a string "name". "text"
nodes contain only a "content" string.
METHODS
"instance()"
Returns an instance of the tree parser.
"new( options... )"
Creates a new parser. Valid options include "process_ns" to process namespaces.
"parse($xml)"
Parses the xml in $xml and returns the tree as a hash ref.
AUTHOR
Copyright (C) 2004-2008, Cal Henderson, <cal@iamcal.com>
SEE ALSO
XML::Parser::Lite.
perl v5.12.3 2011-06-04 XML::Parser::Lite::Tree(3pm)