Menu

How to delete duplicates? xml version 1.1?

Help
mr.duck
2013-04-27
2013-09-03
  • mr.duck

    mr.duck - 2013-04-27

    Is it possible to delete duplicate parts in an xml file? This forum doesn't use the normal code tags, so I don't know how to paste an example. Try and imagine an xml file with these 3 blocks...

    /xml/table/rec id="2"/numField, stringField
    /xml/table/rec id="2"/numField, stringField
    /xml/table/rec id="3"/numField, stringField

    Can the duplicate block be deleted to give...

    /xml/table/rec id="2"/numField, stringField
    /xml/table/rec id="3"/numField, stringField

    Also quick question, why does an xml file with in it give the error "Unseported version '1.1'"? Is there anything I can do about that?

     
  • Noam Postavsky

    Noam Postavsky - 2013-09-03

    Sorry, I somehow missed this post. The forum now uses markdown, see https://sourceforge.net/p/xmlstar/discussion/markdown_syntax.

    Given this

        <xml>
          <table>
            <rec id="2">
              <numField>1</numField>
              <stringField>one</stringField>
            </rec>
            <rec id="2">
              <numField>2</numField>
              <stringField>two</stringField>
            </rec>
            <rec id="3">
              <numField>3</numField>
              <stringField>three</stringField>
            </rec>
          </table>
        </xml>
    

    xmlstarlet ed -d "//rec[@id = 2][position() > 1]" table.xml gives

        <xml>
          <table>
            <rec id="2">
              <numField>1</numField>
              <stringField>one</stringField>
            </rec>
            <rec id="3">
              <numField>3</numField>
              <stringField>three</stringField>
            </rec>
          </table>
        </xml>
    

    I can't think of an easy way to deduplicate all ids though.

    Also quick question, why does an xml file with in > it give the error "Unseported version '1.1'"? Is there anything I can do about that?

    The underlying libxml is giving this error. You can either change to version 1.0, or use -q option to suppress all errors. Ideally libxml would be updated to support version 1.1, but I don't think that's likely to happen...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.