Domanda

Quindi sto scrivendo un codice di generazione di XML, e ha scoperto che il seguente valore di attributo è stato rovinare la formattazione XML:

"Jim/Bob"

Così ho guardato negli Enti XML utilizzati come sequenze di fuga e ogni lista che ho visto non ha incluso uno per la barra. Mi sto perdendo qualcosa di ovvio qui? Sembra che il genere di cosa che ci si vuole scappare ...

È stato utile?

Soluzione

La barra è valida come è e non ha bisogno di ulteriore codifica.

Gli unici caratteri riservati sono:

>
<
&
%

Per ancora più entità XML - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Altri suggerimenti

Lo so si è scoperto che questo non era il problema, ma ho pensato che sarebbe stato utile ricordare che, oltre alla risposta di bobince, la Frazione Slash sguardi entità HTML &frasl; proprio come una barra . Nel caso in cui nessuno raggiungere la pagina in realtà fa vuole un'entità HTML per qualcosa che rappresenta una barra.

There's no predefined entity reference for it, but you can use a character reference: “&#47;”.

However, you don't need to escape / for inclusion in XML. You might have to include it for inclusion in something else, for example a URI path part. But then you'd have to escape it for that format first; the application that picks up the URI wouldn't have any way to know if you'd encoded it in the XML or not.

I don't think the comments in this thread are entirely correct since if you use a schema (XSD) you could define elements with names Jim, Bob and Jim/Bob without any issues. But then when you want to define the element and entity:

<names>
  <Jim>Carrey</Jim>
  <Bob>Jones</Bob>
  <Jim/Bob>Six figured Hillbilly</Jim/Bob>
</names>

The problems are obvious.

FYI although a slash is valid XML, watch out how it's being used downstream. We used it for connecting to an azure service bus queue. Azure itself generated keys with slashes in the connection strings, but then broke silently when we tried to use them. Escaping them with “&#47;” made it work

"Jim&#47;Bob"

I can't see why a value of "Jim/Bob" would need escaping or cause XML any problems at all.

You probably have a constrained attribute, as defined in the XML Schema.

I do not know what you mean by XML formatting.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top