How to track the opened tags in xml using perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to track the opened tags in xml using perl?
# 1  
Old 05-26-2011
How to track the opened tags in xml using perl?

Hi,

I have an xml file like this: I am using xml::dom also and libxml.

Code:
<Nodes>
      <Node>
            <NodeName>MainContent</NodeName>
            <data>1.csv</data>
             <Node>
                  <NodeName>Status</NodeName>
                  <IsWrapper/>
                  <Node>
                        <NodeName>dummy</NodeName>
                        <data>STATUS.csv</data>
                  </Node>
            </Node>
</Node>			
</Nodes>

The file contains the main node called Nodes under that all the things to placed. The node name dummy indicates that dummy node name
should not be written to xml file. IsWrapper is creating a new node.

How to check if the node is opened or not in the following example.

Here MainContent node is opened under that Status is an another node. The status node to closed first and then the main content.

In other words how to close the tags i.e opened.?

How to ensure that there is proper closing and opening tags according to the xml file?

The source file will be like this xml file only?

How can i handle this?

Help is very much required.

Regards
Vanitha

Last edited by pludi; 05-26-2011 at 07:44 AM..
# 2  
Old 05-26-2011
Well, usually we use the PERL sax parser modules not home brew! They call you as tags are opened and closed, so you can deal with attributes and content.

Make an array string variable I_AM_IN and a depth integer variable xml_depth to index it, and keep track of where you are. Use them in debug or error log messages, presented as: /$I_AM_IN[0]/$I_AM_IN[1] . . .
# 3  
Old 05-27-2011
Quote:
Originally Posted by DGPickett
Well, usually we use the PERL sax parser modules not home brew! They call you as tags are opened and closed, so you can deal with attributes and content.

Make an array string variable I_AM_IN and a depth integer variable xml_depth to index it, and keep track of where you are. Use them in debug or error log messages, presented as: /$I_AM_IN[0]/$I_AM_IN[1] . . .
Hi,

Thanks for the reply.

Can u give a small code snippet it will be helpful to me.

Regards
Vanitha
# 4  
Old 05-27-2011
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

3. Shell Programming and Scripting

Perl : to split the tags from xml file

I do have an xml sheet as below where I need the perl script to filter only the hyperlink tags. <cols><col min="1" max="1" width="30.5703125" customWidth="1"/><col min="2" max="2" width="7.140625" bestFit="1" customWidth="1"/> <col min="3" max="3" width="32.28515625" bestFit="1"... (3 Replies)
Discussion started by: scriptscript
3 Replies

4. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

5. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

6. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

7. Shell Programming and Scripting

How to get all the xml tags in perl?

Hi, I have 2 questions: a) Does getElementsByTagName in xml takes more time? b) If it takes more time what are the other alternatives used to get the tag names? For example: <Student> <Studname>aaa</Studname> <Studno>123</Studno> </Student> This is just a sample data. The file... (2 Replies)
Discussion started by: vanitham
2 Replies

8. Shell Programming and Scripting

How to keep track of counter dynamically in perl?

Hi, I have to perform the two things; a) Have to check the previous counter value in the file. b) After some processess are runned again i have to check the same counter value in the same file. Here is the file contents. #File contents of file.txt CounterValue: 0 Here is the... (2 Replies)
Discussion started by: vanitham
2 Replies

9. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies

10. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies
Login or Register to Ask a Question