You are viewing limited content. For full access, please sign in.

Question

Question

Ampersand (&) in XML Error

asked on May 6, 2021

I am using Import Agent to read XML's from a network folder and import documents into the repository. It works fine BUT, if the field value in the XML contains an AMpersand (&), the document errors out. See below:

 

This will error out:

 <LF:field_value name="Agent Name">Customer 1 & Customer 2</LF:field_value>

This works fine:

 <LF:field_value name="Agent Name">Customer 1, Customer 2</LF:field_value>

I am creating the XML from another program.

I have two questions:

  1. Should I have it (the other program) automatically replace ampersands with another value,
  2. Are their any other characters that Import Agent doesn't like in XML's as well
0 0

Replies

replied on May 6, 2021 Show version history

The error is not exactly a problem with Import Agent not liking the value(s), it's more of an issue with what characters are legal/illegal in XML as a standard.

There's a range of "legal" characters in XML so it's hard to provide a full list of what's not allowed, but your most common issues would probably come from <, >, and &

Illegal characters should be replaced with encoded values when the XML is created to avoid the error and ensure you end up with a "legal" XML document.

< = &lt;

> = &gt;

& = &amp;

Depending on the application, you might have options to encode the content automatically so you don't need to write code that checks for every possible illegal character.

For example, if you create XML files as pure text, you get the content as-is, illegal characters and all, but if you use something like the XmlWriter or Linq to XML in .NET it will encode everything automatically.

 

Extensible Markup Language (XML) 1.0 (Fifth Edition) (w3.org)

3 0
You are not allowed to follow up in this post.

Sign in to reply to this post.