py_201:

Assuming you're talking about using code to edit your XML file, if you try to avoid the XML parser part you'll only have to reinvent it yourself (poorly, as it's harder than you think to make an XML parser). Don't worry about how much time it takes: That's a premature optimization. Until you know it's too slow, don't worry about it. Also, there are some XML parsers available that are pretty fast, so it shouldn't be an issue anyway.

But that's now why I'm writing. What I really wanted to do was suggest that you change your XML a bit. You're using tags <ip1>, <ip2>, etc., in your <ips> section. You should just use <ip> -- if you want to number them, then give them a number or name attribute like this: <ip id="1"> or have another sub-node to give it a name:

<ips> <ip> <name>foo</name> <from></from> <to></to> </ip> </ips>

There are several problems with dynamically changing your node tags. The most problematic is that any programs processing your XML documents are going to have to have some "magic" to interpret the document because you're trying to make a tag convey two pieces of information: (1) that this is an ip item, and (2) which ip item it is.

...roboticus

In reply to Re: Edit XML File in perl by roboticus
in thread Edit XML File in perl by py_201

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.