none
When updating an XML document using XMLDocument load()/save() it changes ' to ". RRS feed

  • Pregunta

  • I have a script that goes though a repo and updates a large amount of .csproj and .targets files that are in xml format. When updating a document using XMLDocument load()/save() it changes ' to " on elements I haven't changed. This doesn't break anything persay, but makes PRs a bother to go through. especially cause there are a lot of them. is there a way to have that not changed? I already have perserverwhitespace set to true on the document. Thanks for any feedback!
    jueves, 16 de enero de 2020 15:56

Todas las respuestas

  • The double quotes are normal for XML so there is no need to bother to change them.  The two are equivalent in XML.


    \_(ツ)_/

    jueves, 16 de enero de 2020 16:21
    Moderador
  • Yeah, it will just make my prs bigger. lol again, not the end of the world. was just curious if there was an attribute to keep it like it was. Thank you!
    jueves, 16 de enero de 2020 16:36
  • Just a note. The standard for XML and HTML is double quotes.  Most doc writers will enforce the standard.  The use of single quotes is mostly intended for use in compound syntax to allow embedding of quotes in statements.

    The XML standard causes most vendors to convert single quotes.

    Also the output and the object never sees quotes.  They are added when the XML is viewed and added as the XML is written.

    If you create a document or element the quoes will be chnaged as you add elements.

    Example:

    PS C:\scripts> $x=[xml]"<x y='vvvv'/>"
    PS C:\scripts> $x.OuterXml
    <x y="vvvv" />

    Note the quotes are already changed.  There is no way to prevent this or to specify a quote character.


    \_(ツ)_/

    jueves, 16 de enero de 2020 16:37
    Moderador
  • Yeah, it will just make my prs bigger. lol again, not the end of the world. was just curious if there was an attribute to keep it like it was. Thank you!

    What are your PRS?  Why would it make them bigger? There is no size difference between the two characters.


    \_(ツ)_/

    jueves, 16 de enero de 2020 16:40
    Moderador
  • O sorry about that. My Git repo pull requests. when those things are changed, it just makes reviewing the pull requests longer cause it shows changes that weren't really intended. But its something I can live with, as stated above if that is the xml standard to use double quotes.

    • Editado cortez77 jueves, 16 de enero de 2020 16:57
    jueves, 16 de enero de 2020 16:55
  • Why are you using single quotes to begin with?  

    You can hand edit and it will prevent changes.  I am surprised it would see that as a change.  Ask them to check the coding of the validater to  not do text level comparison.  The validation should only be done with XML against the schema and the data in the XML.  That is one of the main reasons for using XML.  Simple text differences can be ignored.  Sounds like the programmers didn't know much about XML.  


    \_(ツ)_/

    jueves, 16 de enero de 2020 17:46
    Moderador