Results 1 to 13 of 13
Thread: dig XML
- 04-05-2012, 02:16 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
dig XML
Hello,
am doing one project in NetBeans whee I need to read xml file and search for all "index=" words, for example:
<param name="search"><![CDATA[index=linux AND host="$host$" AND....... package AS Package]]></param>
After I search it I need to collect it and witte it in new xml file but without words that are inside of $ and delete all AND words. I know that I have to do it somehow with regex, but please can u give me any tips, code, idea?
Thanks a lot!
- 04-05-2012, 04:09 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
Or can anyone tell me how this python code re-make into Java code
import re
datoteka = open(r'linux_installed_packages.xml', 'r')
podaci = datoteka.read()
datoteka.close()
searchevi = re.findall(r'<param name="search">.*?</param>', podaci)
for search in searchevi:
search = re.search(r'<param name="search">(.*?)</param>', search)
search = search.group(1)
search = re.sub('^\<\!\[CDATA\[', '',search)
search = re.sub('\]\]\>', '', search)
search = re.sub(r'\sAND\s', ' ', search)
search = re.sub(r'\s{1}[^\=]+=\"?\$[^\$]+\$\"?\s', ' ', search)
print search
}
I know only how to open file in Java, but I dont knwo how to form regex....
- 04-09-2012, 08:49 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
Come on... any1?
- 04-12-2012, 11:15 AM #4
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
I managed...
This is curent code.
//Pattern regex = Pattern.compile("module", Pattern.MULTILINE | Pattern.DOTALL);
Pattern regex = Pattern.compile("<param name=\"search\">(.*?)</param>", Pattern.MULTILINE);
Matcher matcher = regex.matcher(editedXML);
while(matcher.find())
{
String search = matcher.group(1);
Pattern regexSearch = Pattern.compile("\\s{1}[^\\=\\s]+=\\\"?\\$[^\\$]+\\$\\\"?", Pattern.MULTILINE);
Matcher matcherSearch = regexSearch.matcher(search);
String searchParsed = search;
while(matcherSearch.find()){
String foundPattern = matcherSearch.group(0);
searchParsed = searchParsed.replace((CharSequence) foundPattern, (CharSequence) "");
//System.out.println("Rezultat: " + searchParsed);
}
String novistr = searchParsed;
String novieditedXML = novistr.replace(" AND AND", " AND");
System.out.println("Rezultat: " + novieditedXML);
}
I made several regex and substring replacements on my xml file. Result is several commands... and the problem is how to make in java "chooser which select do I want to perform in cmd". Any idea, thanks!
- 04-12-2012, 11:26 AM #5
Re: dig XML
Cross posted
xml - Python code re-make to Java code - Stack Overflow
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-12-2012, 11:31 AM #6
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
So what? I figure that part as you can see in my previous post, now I need to collect my results and make program to chose which one do I want to perform.
- 04-12-2012, 02:33 PM #7
Re: dig XML
I see that you reported Darryl for "trolling", when all he was doing was offering the courteousness that you refused to offer. Everybody is doing this for free, in their spare time, so we don't like to waste time answering questions that have already been answered. The easy way to show us some basic politeness was to simply let us know where else you've asked the question. If you value our time so little, why would anyone want to help you out?
Please see the link in my signature on asking questions the smart way before you post again.Last edited by KevinWorkman; 04-12-2012 at 02:37 PM.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2012, 02:37 PM #8
Re: dig XML
Why do they call it rush hour when nothing moves? - Robin Williams
- 04-12-2012, 02:49 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
yep do it..spamm it out..whole topic.. atleast some1 is writting anything as replay...
Point was, he wasted his time searchign on google if I wrote same somewhere else..... if u dont want to help then dont troll pls or write "smart a*" msgs.... also tbh I would rather read some book then waste time writting "How to Ask Questions the Smart Way"
- 04-12-2012, 02:54 PM #10
Re: dig XML
This thread is going nowhere with your attitude. Did you read the link on asking smart questions? I assume not, since you're still writing like you're texting your girlfriend instead of asking a question on a technical forum. Again, if you can't take the time to ask an answerable question without giving off an attitude, why would anyone want to take their time to help you?
Many of us frequent multiple forums throughout the day, which is how many crossposts are discovered. I really suggest you stop insulting the people who would help you, but I guess it's really up to you.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2012, 03:04 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0
Re: dig XML
Where to move my topic, where is technical part of forum?
- 04-12-2012, 03:14 PM #12
Re: dig XML
The entire forum is technical in nature. That's my point. That's why things like rudeness and text-message abbreviations stick out so much. You haven't really asked a technical question though. You've stated some demands (again, using text-message speak, which makes it hard to read), asked for some code, and then bumped your thread, again asking a general "how do I do this" type question instead of an actual technical question. Then you started being rude to somebody who might have helped you, and here we are. That's why I gave you the link on asking questions the smart way.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2012, 03:35 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 8
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks