Solved

XML find and Replace root element

Posted on 2008-10-18
9
946 Views
Last Modified: 2013-12-21
Hi All,

I have a XML file which i want to search an element with two set of values in the PCDATA.
The element is CustomNoteTypeName and can have two values i.e. DBHA or DAKO.
If these two values are found then change the root element of the XML file to something other what is at present if not found let the XML files process the way are to be.

Kindly let me know if you need more information from my end.

Thanks

Karan
0
Comment
Question by:Pankaj_Sachdeva
  • 5
  • 4
9 Comments
 

Author Comment

by:Pankaj_Sachdeva
ID: 22748571
Can someone please throw some light on the above issue. I would be really grateful.

Thanks
Karan
0
 
LVL 62

Expert Comment

by:gheist
ID: 22753194
Let me suggest libxml's xmllint. Hope you have time to write DTD for XML you expect so that parser/validator is able to clean up.
Apache may ship some better tools in java, I am not big fan of.

libxml2 download here, do not compile.

http://www-304.ibm.com/jct03004c/systems/p/os/aix/linux/toolbox/download.html
0
 

Author Comment

by:Pankaj_Sachdeva
ID: 22755276
xmllint is not supported by my client's AIX machine. I cannot add anything on top of the server.

All i am looking for is a simple awk which does the job. I have tried the below but its not helping me somehow:-

{
  if ( index($0, "<NumberType>ZAP</NumberType>") )
   {
                  gsub(/XmlInterchange/,"XmlInterchange_new",$0);
          print $0;
   }
  else
   {
                print $0;
}
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 62

Expert Comment

by:gheist
ID: 22755867
Linux affinity components can be installed and uninstalled at will and are somewhat supported by IBM. An tou may install libxml2/xmllint on windows (or use one already present on Linux wg via vmware or virtualbox)to see whether it helps. If you post example of source and fixed XML I might get luckier with awk/sed/perl.
0
 

Author Comment

by:Pankaj_Sachdeva
ID: 22755884
I am attaching the example file. It would be great if you could check my above code as i am in need of awk code which fits in well to the present setup.

Thanks

Karan
BL-DAKOSY-C00003168-200810181657.txt
0
 
LVL 62

Expert Comment

by:gheist
ID: 22756033
Is it just as simple as replacing one string with another?

sed s/'>WWW<'/'>XXX<'/g

?
0
 

Author Comment

by:Pankaj_Sachdeva
ID: 22756048
I think your not getting my point...I need to check for a specific element and the value inside a XML and then replace the root element.

Regards
Karan
0
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 22756117
Then you have to use XML parser like apache xerces (Java) or libxml.
AIX has not even got Unicode capable sed/awk/grep, that basically makes it unable to parse XML.
0
 

Author Closing Comment

by:Pankaj_Sachdeva
ID: 31507404
thanks
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question