16

I have XML data which contains a long attribute value. The value does not contain white space characters. I want to format the XML for readability by splitting the XML text so that the line does not exceed a maximum number of column.
Is there any mean to accomplish this? Is there any break character that I can put at each end of line so that the XML parser does not consider it as a white space (like underscore character in visual basic)?

For example:

<element attribute="this_is_a_very_long_text_attribute_value_that_I_want_to_split_on multiple_line_for_readability"/>

I want to have something like:

<element attribute="this_is_a_very_long
_text_attribute_value_that_I_want_to_split
_on multiple_line_for_readability"/>
Gaël Mo
  • 185
  • 1
  • 1
  • 6
  • you realise that the two attributes are different values if you wanted to match on them, and that maybe if you have a long value like that it would be better in an element inner text without underscores? There is no character you can use (XML will rightly never split an attribute as it breaks it). Beyond that, yes it is possible depending on what language you are processing the file in – Woody Jul 09 '12 at 10:58
  • My attribute value is in fact a list of smaller values separated by semicolons. In this case, it seems more appropriate to use sub elements. I use this to handle configuration parameters in the form of key/value pairs among which some have the form of a list of strings. So, it is not possible in my case to use an element inner text without doing important changes to the file format. Thanks for your answer anyway, I just wanted to make sure I didn't miss something from the XML specification. – Gaël Mo Jul 11 '12 at 14:15
  • Related: [Are line breaks in XML attribute values allowed?](https://stackoverflow.com/q/449627/3357935) – Stevoisiak Nov 15 '17 at 18:15

2 Answers2

4

there is no provision in XML itself for line feed character in Attribute Values
however this can be done depending upon the IDE you are using this to write
ie. if you are using Visual Studio there is a provision to break lines and is handled by the IDE itself
but if you are using some low level text editor like Notepad this cant be done
you should probably check in the documentation of your XML editor

Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • 2
    Really? [This answer](http://stackoverflow.com/a/449647/33080) says otherwise; newlines in attribute values are supposed to be accepted by a compliant XML parser. – Roman Starkov Apr 25 '14 at 13:36
  • 1
    if you will read the question this guy does not what to get multi line he has a long line which he wants to read in multiple line – Parv Sharma Apr 25 '14 at 15:46
  • If you read the next response in the answer above, it talks about normalization of attributes. New lines will typically be converted to spaces. \n is not the same as – Dorrin May 27 '14 at 13:52
-1

Well there is a way: In short just use tab's instead of space. For more please look at this answer. https://stackoverflow.com/a/38880984/3135511

Hmm well IDE like the Chrome Developer Tool or Visual Studio may trap and limit you in doing so, but some ordinary editor will get this done and the html/xml will handle it.

Community
  • 1
  • 1
Nadu
  • 2,401
  • 1
  • 25
  • 30