|
|
|||||||
Hi Guys, I'm not sure what happened to my last post, but it didn't seem to post early this morning, so I am going to try this again. I need to be able to use the KIX script to rewrite what is in the following tag: and become (replace with): Does anyone have any ideas to help me out? Thanks! Faithful |
||||||||
|
|
|||||||
read the file in and write it out and use join() split() to replace the text. |
||||||||
|
|
|||||||
You can't just replace it like you could with an ini file? [CODE]<Receipt value='YES'>G:\Windows\NewFolder\</Receipt>[/CODE] It's a rather large file, and I just want to modify the one entry. Any other ideas or is that they only way? Thanks, Faithful |
||||||||
|
|
|||||||
Faithfulman, what Jooel is saying is that a .xml file is like a .txt file and can be opened and then read each line looking for the appropriate text then once you find it write the line back as you desire then close the file and your done. |
||||||||
|
|
|||||||
I really have not done too much of this. Can someone give me some example or some guidance? Thanks, Faithful |
||||||||
|
|
|||||||
Something like this. Not tested but it looks like it should work just fine. Code:
[edit] Hmmmm..... There could be an issue with paths that have C:\windows\folderName\ in it and should not be changed. Depends on your situation and if all the lines that have C:\windows\folderName\ in it should be changed. [/edit] |
||||||||
|
|
|||||||
Code didn't take so I have posted the issue at hand down below: |
||||||||
|
|
|||||||
[CODE] tags need to be in lowercase. |
||||||||
|
|
|||||||
Okay, from this Quote: to Quote: Using This Code:
|
||||||||
|
|
|||||||
Does anyone have any ideas on this?? |
||||||||
|
|
|||||||
What is it doing or not doing that you want it to do? |
||||||||
|
|
|||||||
Quote: I am missing something, they both look exactly the same to me. |
||||||||
|
|
|||||||
Oops made a mistake in the code I posted above. Fixed the code you posted and tested it. Works ok like this. Code:
|
||||||||
|
|
|||||||
mart, 'Else' is redundant Code:
|
||||||||
|
|
|||||||
Yeah I know. Didn't feel like a game of golf so just typed an else for fun |
||||||||
|
|
|||||||
Okay guys, yes this did work ... but not exactly how I thought it was going to. I want to be able to take whatever is in the "<'test'>" tags and replace it with whatever I choose to. So basically, if I have this: Code: < Receipt > or if I have Code: < Receipt > I want to be able to strip that whole thing out and replace it with: Code: < Receipt > Is there a way to just find the line that holds the "< test >" tags and replace what's between the "< test >" tags? Thanks, Faithful P.S. The forum keeps removing my tags as soon as post, sorry about the extra spaces. |
||||||||
|
|
|||||||
Anyone have any thoughts on this? |
||||||||
|
|
|||||||
You present a very artificial albeit simple example. In that case you could simply replace the whole line. What if it were a multiline value? |
||||||||
|
|
|||||||
Right but the line could be many different things. So, If I could replace the whole line that would be fine. Just not sure how to go about replacing the whole line? Any thoughts? Thanks, Faithful |
||||||||
|
|
|||||||
The code Benny gave you does just that... replaces whatever with something else. |
||||||||
|
|
|||||||
Did some stuff with xml reading and writing some time ago. I'll se if I can brew a script that actually reads and writes the file as xml and not as plain text. Gimme and hour or so. Stand by..... BTW if you want to replace the whole line you could do: Code:
|
||||||||
|
|
|||||||
Do you have the entire structure of the XML file at hand? If so can you post it or mail (see profile for mail address) it to me? I have a script (thanx to Shawn, Jim and Jose) to write a new xml file using kix. |
||||||||
|
|
|||||||
You can start reading and learning more about it here. RFC: XML UDF's jtokach http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=135678 RFC: ReadXmlString/WriteXmlString http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=134644 RFC: fnLoadXML() - Loads & validates XML documents http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB2&Number=134643 |
||||||||
|
|
|||||||
No it does not. It replaces a specific string with something else. I need to be able to replace < receipt >this is one text < /receipt > with < receipt >this is another text < /receipt > even if the XML file looks like < receipt > < /receipt > Or if it looks like < receipt >this is another another text < /receipt > I need the script look for line that says < receipt > and be able to replace that with what I want it to be dynamically. Every user's configuration will be slightly different. Currently his script looks like this: Code:
But I don't want to just look for "This is too cool" ... I need to replace that whole line. His code just replaces the text that it searches for. I want to replace everything between < test > and < /test > |
||||||||
|
|
|||||||
Slightly different code is needed for that. Code:
|
||||||||
|
|
|||||||
Doc, That's just where I based my xml writing scrip on. An example from the posts referred to that shows how to write an entirely new XML file. If you know the new structure and values of the xml file you could do something like this (thanx to Shawn, Jose and Jim). Remember that reading this XML stuff is very, VERY, VERY , case sensitive. I learned the hard way and that s#cked. Code:
|
||||||||
|
|
|||||||
Hi Mart, Your code does not work: Code:
All it does is copy the xml file. I think the problem may be that you are trying to match the line with Code:
The problem is sometimes it is "This is cool" and other times it might be something else. I just want to find the code that has the " Thanks, Faithful |
||||||||
|
|
|||||||
Ok, an other option. If I understand you last post correctly this should do the trick. This one checks if both the start and end test tags are in the line. If so it changes the contents of $line to the new stuff including the start and end test tags. Both the tags should be on the same line with the value if not this script fails. A rewrite of the entire xml file with a modified to your situation version of the script I posted above is the road I would try to walk on. Reading and writing xml with kix is new and has not been heavily used before afaik. Shawn, Jim and Jose did some stuff with this but it kind of faded out a little. Recently I picked up reading and writing xml as xml and not text using kix again because we have several projects at work that we can use this for but for me it's also a path full of surprises and new stuff. Learning something new almost each time I use it. I changed the brackets around test and /test because the board keeps eating them. You should change it back to the proper brackets before using the code. Code:
|
||||||||
|
|
|||||||
Okay, this looks like it will do the trick. SO, the last question is ... what if I just want to update the existing file and not create a new one? Thanks for all your help! Faithful |
||||||||
|
|
|||||||
Hmmmmm..... Damn now you got me pinned in a dark and scary corner Have not found a way to do this (yet). I'm pretty sure it can be done but I did not found how to make that work yet. I guess reading the entire source file line by line, writing the outcome to a new file, renaming the original file to .old (or delete it if you are seeking trouble) and renaming the new file to the name the original file had is the quickest way. |
||||||||
|
|
|||||||
Okay, ... so what about escaping quotes? I have the following code: Code:
It doesn't seem to like the quotes around YES. Is there a way to escape the quotations so the print in the new file? Thanks, Faithful |
||||||||
|
|
|||||||
If you were wondering what I was talking about before ... the code tags on this forum aren't working ... so I edited my post above. |
||||||||
|
|
|||||||
if you want to be able to modify a file, then you will need to read in the entire file storing it in an array, modify the array, delete the file then rewrite the file back from the array. you could use a string instead of an array but you are limited to aprox 32,000 chrs per string, you would have to create a stack of strings to accommodate a length greater then 32,000 chrs. |
||||||||
|
|
|||||||
Change it to this and it'll work. See the single quotes around the string. The double quotes inside the string will now stay as they are. Code:
It's midnight here and I think I hear my bed calling me to get my #ss upstairs and go to sleep. See you guys in the morning. |
||||||||
|
|
|||||||
Thanks Mart, I appreciate your help on this. Can anyone help me know how to rename a file ? After I have done this ... I want to be able to delete file number 1 and rename file 2 to be named the same as file number 1. This is what I have so far: del $sourcefile ren C:\newSourceFile.xml | XMLfile.xml The delete works, but the rename gives me an error. Any help would be appreciated! Thanks, Faithful |
||||||||
|
|
|||||||
There is no rename in KiXtart. You would have to SHELL out to %comspec% and rename the file. Please take a look at SHELL / RUN in the manual and here in the FAQ forum for further information if needed. |
||||||||
|
|
|||||||
Quote: Sure there is. RTFM Move. http://www.kixtart.org/manual_index.html#_Toc146265696 |
||||||||
|
|
|||||||
Sorry, yes you're right. I just rarely use it so forgot about that method. |
||||||||
|
|
|||||||
So Code:
would work. Better (safer) would be Code:
|