Community
    • Login

    Merging two tags into one in XML

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 3 Posters 777 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Дмитрий ПрокопьевД Offline
      Дмитрий Прокопьев
      last edited by

      Good afternoon! I’ve been racking my head for the second day, I can’t find a solution to the problem
      I have this XML big file:

      	<name>offer</name>
      	 <id>111</id>
      	<price>111</price>
      	<edizm>м2</edizm>
      	<width>7.5</width>
      	<length>30</length>
      

      I need 2 lines

      	<width>7.5</width>
      	<length>30</length>
      

      So that in the end there would be:

      <size>7.5x30</size>
      

      If you look for one line, he finds it, but he doesn’t want to try two.

      SEARCH <width>(?<width>[^"]+)</width>\n\r<length>(?<length>[^"]+)</length>
      REPLACE <size>$1x$2</size> or <size>/1x/2</size>
      

      Please tell me where is my mistake?

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA Offline
        Alan Kilborn @Дмитрий Прокопьев
        last edited by

        @Дмитрий-Прокопьев

        I might try it this way:

        Find: (?-is)<width>([\d.]+).+>\R\h+<length>([\d.]+).+
        Replace: <size>$1x$2</size>
        Search mode: Regular expression

        1 Reply Last reply Reply Quote 2
        • guy038G Offline
          guy038
          last edited by guy038

          Hello, @дмитрий-прокопьев, @alan-kilborn and All,

          Very easy with regexes !

          So use the following S/R :

          SEARCH (?-is)^(\h*)<width>(.+)</width>\R\h+<length>(.+)</length>

          REPLACE $1<size>$2x$3</size>


          Notes :

          • First, in the search regex, the in-line modifiers (?-is) :

            • Force the search to be sensitive to case

            • Force the regex engine to consider that the . regex character represents a standard character ( NOT any EOL chars )

          • Then, the ^ syntax refers to the beginning of any line

          • Then (\h*) represents any leading spaces and/or tabulations or none, stored as group 1

          • Except for the literal parts ( <width>, <width>, <length> and </length> ) two syntaxes are to be considered :

            • (.+) which represents a non-null range of any standard character(s), stored, successively, as groups 2 and 3

            • \R, which represents any kind of line -breaks ( \r\n for Windows files, \n for Unix files or \r for MAC files )

          • In the replacement regex, three syntaxes are possible :

            • \1<size>\2x\3</size>

            • $1<size>$2x$3</size>

            • ${1}<size>${2}x${3}</size>

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 2
          • Дмитрий ПрокопьевД Offline
            Дмитрий Прокопьев
            last edited by

            Thank you very much, it helped a lot!

            1 Reply Last reply Reply Quote 2

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors