Solved

XML find and Replace root element

Posted on 2008-10-18
9
943 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
Comment Utility
Can someone please throw some light on the above issue. I would be really grateful.

Thanks
Karan
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
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
Comment Utility
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
 
LVL 61

Expert Comment

by:gheist
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Pankaj_Sachdeva
Comment Utility
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 61

Expert Comment

by:gheist
Comment Utility
Is it just as simple as replacing one string with another?

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

?
0
 

Author Comment

by:Pankaj_Sachdeva
Comment Utility
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 61

Accepted Solution

by:
gheist earned 500 total points
Comment Utility
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
Comment Utility
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now