find un-closed tags in XML files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find un-closed tags in XML files
# 1  
Old 01-03-2013
find un-closed tags in XML files

Hi All,

I am trying to validate XMLs from a folder:

Input Directory having multiple XML files:

File1.xml
Code:
<Root>
  <Parent>
     <Child Name="One">
        <Foo>...</Foo>
        <Bar>...</Bar>
        <Baz>...</Baz>
     </Child>
     <Child Name="Two">
        <Foo>...</Foo>
        <Bar>...</Bar>

File2.xml
Code:
<Root>
  <Parent>
     <Child Name="One">
        <Foo>...</Foo>
        <Bar>...</Bar>
        <Baz>...</Baz>
     </Child>
     <Child Name="Two">
        <Foo>...
        <Bar>...</Bar>
     </Child>
  </Parent>
</Root>

File3.xml
Code:
<Root>
  <Parent>
     <Child Name="One">
        <Foo>...</Foo>
        <Bar>...</Bar>
        <Baz>...</Baz>
     </Child>
     <Child Name="Two">
        <Foo>...</Foo>
        <Bar>...</Bar>
     </Child>
  </Parent>
</Root>

My output should be:
File1.xml & File2.xml doesn't having proper closed tags these files have to store in Folder1

File3.xml having proper closed tags so these file has to be stored in Folder2

I don't know how to start with.. could you please help in this.

Thanks in advance

Regards,
Ulf
# 2  
Old 01-03-2013
Before we start dreaming up awk or sed solutions for your request, you should try to find xml specific tools doing exactly this for you - and I'm sure there will be abundant thereof, on these fora, or found by google.
# 3  
Old 01-03-2013
Actually what you are trying to do is check that your XML is "well-formed". Well-formed and valid are two completely different concepts in XML. A document, i.e. file containing your XML, can be well-formed but not valid. However if it is a valid document, by definition it must be well-formed.

Do an Internet search for "check XML well-formedness" and you should find some utilities that will do what you want. Such tools include xmlproc and xmlproc_val.

Last edited by fpmurphy; 01-04-2013 at 09:09 AM..
# 4  
Old 01-04-2013
Thanks all I will check for it.
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 a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

3. Shell Programming and Scripting

How to do find differences between 2 XML Files?

Hello All, Requirement is to compare 2 XML files and see if there are any differences but from some of the providers We are receiving UTF-16 formatted XML file with no end of line as shown below. Excerpt of data file: ÿþ<^@?^@x^@m^@l^@ ^@v^@e^@r^@s^@i^@o^@n^@=^@"^@1^@.^@0^@"^@... (11 Replies)
Discussion started by: Ariean
11 Replies

4. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

5. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

6. 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

7. 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

8. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

9. Windows & DOS: Issues & Discussions

Renaming files with strings from xml tags

Hello! I need to rename 400+ xml files. The name of the specific file is contained in a xml tag in the file itself. The batch file should rename all these files with strings found in xml tags. Every xml file has the following tags: <footnote><para>FILENAME</para></footnote> I have to get... (3 Replies)
Discussion started by: degoor
3 Replies

10. Shell Programming and Scripting

how to get data from xml files tags(from data tags)

i have a file like <fruits> <apple>redcolor<\apple> <bana:rolleyes:na>yellow color and it is<\banana> </fruits> i need a text between apple and bannana ans so on.... how to read a text between a tags it multiple tags with differnt names (9 Replies)
Discussion started by: pvr_satya
9 Replies
Login or Register to Ask a Question