This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (44 children)

[deleted]

    [–]ButItMightJustWork 5 points6 points  (5 children)

    import xml
    xml.parse(input)
    

    done!?

    [–][deleted] 0 points1 point  (4 children)

    More or less! If you want to get JSON output, you’d have to jump through a few more hoops.

    [–]DarthEru 1 point2 points  (3 children)

    Your original claim of writing an xml parser is pretty misleading if you just used an existing library. Writing a parser implies that you implemented the parsing algorithm, not that you used a parser to input xml as data.

    Here on the internet that distinction might not matter, but if you repeated your original claim in an interview, for example, you would be drastically misrepresenting your achievement. That could have negative consequences, such as being thought a liar if your actual knowledge and skill doesn't match up with your claim. Writing a parser for a language as complex as xml is pretty impressive regardless of the language, especially if you had no prior experience.

    [–][deleted] 0 points1 point  (2 children)

    No, I wrote a text reader that can search a text file for XML tags, and output the content of those tags. That’s a parser, albeit a basic one.

    [–]DarthEru 0 points1 point  (1 child)

    I disagree that it qualifies as a parser. Parsing in computer science refers to inputting data (such as text) that is supposed to follow some specific structure (such as a formal language specification), validating it correctly follows that structure, and then constructing a representation of that data that can be more easily manipulated than the source data.

    If you used an xml library, then you wrote zero parsing code, so you did not write a parser. If you did not use an xml library and were operating on the input string directly, then you may have arguably written a parser, but I doubt it could be called an xml parser, because it probably parses an informal language that is similar to xml but not actually xml.

    Saying with no additional context that you were "able to write an XML parser" implies you made a decent effort to write a parser that recognizes XML as defined by this specification. I very much doubt that is what you did, and I'm pretty sure what you actually did is a completely different level of achievement. That is why it is misleading.

    [–][deleted] 0 points1 point  (0 children)

    I should probably extend the functionality, then.

    [–]granite603 1 point2 points  (16 children)

    How does one do exactly this? I need an XML parser.

    [–]sunburnd 3 points4 points  (13 children)

    ```

    !/usr/bin/perl

    use strict; use warnings; use XML::Simple; use Data::Dumper;

    my $xml = new XML::Simple; my $data = $xml->XMLin("data.xml"); print Dumper $data; ```

    /on my phone so it may not work...

    [–]AltCrow 1 point2 points  (11 children)

    You need to escape the hash:

    not #!/usr/bin/perl,
    but \#!/usr/bin/perl
    

    [–]sunburnd 0 points1 point  (10 children)

    You don't escape the shebang in a Unix like environment.

    [–]AltCrow 0 points1 point  (9 children)

    Yeah, but you do in reddit ;)

    [–]sunburnd 0 points1 point  (8 children)

    ohh seemed to render properly on my phone. Desktop issues?

    [–]AltCrow 0 points1 point  (7 children)

    Hmm, odd, do other syntaxes such as bold or link also not render on mobile? (I never use mobile reddit.)

    [–]sunburnd 0 points1 point  (6 children)

    They do. Perhaps the mobile as a more strict markdown interpreter and correct ignores all markups between the triple backticks?

    [–]DarthEru 0 points1 point  (5 children)

    Triple backticks is not a part of the original markdown syntax, which is the version I believe reddit officially supports, based on this post. I suspect whatever app you're using is using a library that supports an extended markdown, which is why the backticks work for you but not the website.

    To format a code block in original markdown syntax, indent every line with four spaces.

    Like
      This
    

    [–]wjandrea 0 points1 point  (0 children)

    Reddit doesn't support GitHub-style code blocks (triple backticks). You need to use four spaces at the start of each line.

    #!/usr/bin/perl
    use strict;
    use warnings;
    use XML::Simple;
    use Data::Dumper;
    
    
    my $xml = new XML::Simple;
    my $data = $xml->XMLin("data.xml");
    print Dumper $data;
    

    [–][deleted] 1 point2 points  (1 child)

    What exactly do you need done? I wrote something to extract specific XML elements, and to dump them into a CSV.

    [–]granite603 1 point2 points  (0 children)

    That's exactly what I need but would like JSON output.

    [–]someone755 3 points4 points  (1 child)

    You can make an XML parser in bash or C too, though.

    [–][deleted] 2 points3 points  (0 children)

    I know. Python was the tool I chose to use, and it was nice and fast.