Link to home
Start Free TrialLog in
Avatar of Pankaj_Sachdeva
Pankaj_Sachdeva

asked on

XML find and Replace root element

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
Avatar of Pankaj_Sachdeva
Pankaj_Sachdeva

ASKER

Can someone please throw some light on the above issue. I would be really grateful.

Thanks
Karan
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
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;
}
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.
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
Is it just as simple as replacing one string with another?

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

?
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
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks