#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Probem with tab space when insert a new XML element


    Hi, I am new in editing xml and I have met this problem: I edit xml files using lua commands and when I replace or add a new xml row, next row's tab space (or one empty space character) is disappeared. It is something like:
    Code:
    <some element>
         <child1>
         <child2>
        <new added child> 
    <child 3>
       <child4>
    <some element/>
    Moreover, in the case of a replacement, if there was a comment in that line, it goes in next line alone:
    Code:
    <some element>
         <child1>
         <child2>
        <new added child> 
    <!--comment of replaced child 3-->
       <child4>
    <some element/>
    This is rather a cosmetic problem and does not actually affect the structure of the xml but if there are many such changes I cannot read easily the xml any more and search for other potential mistakes. I tried adding page breaks and such with no luck so far. Is there a solution?

    Thanks!
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    What's your code to insert into the XML? If you're doing it manually then you need to copy whitespace from the next node. Unless it's a closing tag, then you need to add one more level of indentation.

    For example,
    Code:
    <a>
        <b>_
    ____<d>
    </a>
    Code:
    <a>
        <b>_
    ____<c>
        <d>
    </a>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0
    The addition or replacement is happened automatically by a Lua command. Since this command must be in one line what I have to add before or/and after "<c>" so I can have the result (the red spaces) in <d> element? Because the problem appears in the very next line (<d> in your example) and not in the one I add (<c> in your example).
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    Originally Posted by Arispezon
    The addition or replacement is happened automatically by a Lua command.
    Which would be...?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0
    XML.InsertXML("a/b", "<c>", XML.AFTER);

    or if I want <c> to replace <b> it should be:

    XML.InsertXML("a/b", "<c>", XML.REPLACE);
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    It doesn't seem like there's any way to fix the indentation in Lua. At least not according to the documentation.

    A few editors have a Reformat Document-type action, and most XML viewers will present the markup reformatted for you to see...
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0
    O.K. I thought that it was something I didn't know about it..

    Thanks a lot Requinix for your hep.

IMN logo majestic logo threadwatch logo seochat tools logo