Results 1 to 13 of 13

Thread: dig XML

  1. #1
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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!

  2. #2
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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....

  3. #3
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: dig XML

    Come on... any1?

  4. #4
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: dig XML

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default 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 03: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!

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: dig XML

    Quote Originally Posted by KevinWorkman View Post
    I see that you reported Darryl for "trolling"
    Yeah I got that report too. Funny how people know cross posting is rude but go ahead and do it anyway. Nothing else could explain the knee-jerk reaction when it's pointed out, without comment.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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"

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default 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!

  11. #11
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: dig XML

    Where to move my topic, where is technical part of forum?

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default Re: dig XML

    Quote Originally Posted by phys1cx View Post
    Where to move my topic, where is technical part of forum?
    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!

  13. #13
    phys1cx is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: dig XML

    Close this topic, forum is useless.... Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •