正在加载,请稍候…

Decoding XML in Patent Filings: Handling Special Characters and Entities

Practical guide to escaping and unescaping HTML/XML entities when submitting patent electronic files, addressing common 'XML is garbled' issues with worked

When working with XML-formatted patent filings, one of the most common complaints is "the XML looks garbled" or "special characters turned into gibberish." This usually isn't a corruption—it's the raw display of XML entities. Understanding how to properly escape and unescape special characters in XML is crucial for patent professionals, especially when submitting documents to patent offices that require strict XML compliance.

Patent document with XML code on a laptop screen

What Are XML Entities?

XML uses a small set of reserved characters that have special meaning in the markup language. To include these characters as literal text, you must replace them with predefined entities or numeric character references. The five predefined XML entities are:

Character Entity Numeric Reference Description
< &lt; &#60; Less-than sign
> &gt; &#62; Greater-than sign
& &amp; &#38; Ampersand
' &apos; &#39; Apostrophe (single quote)
" &quot; &#34; Quotation mark

In patent documents, you'll often encounter mathematical formulas, chemical symbols, or trademark signs that require these entities. For example, a claim reciting "A composition comprising A & B" must be written as A &amp; B in XML.

Why Patent Filings Demand Proper Escaping

Patent offices like the China National Intellectual Property Administration (CNIPA) and the USPTO now mandate XML format for electronic filings. The XML schema for patent applications (e.g., ST.26 for sequence listings, or the CNIPA's own DTD) strictly enforces well-formedness. A single unescaped ampersand or angle bracket can cause the entire document to be rejected as malformed.

Common Scenarios Where Entities Appear:

  • Chemical formulas: Fe<sub>2</sub>O<sub>3</sub> (note: <sub> tags are markup, but the < in text must be escaped)
  • Mathematical expressions: x < yx &lt; y
  • Trademark symbols: ®&#174; or &reg; (if DTD defines it)
  • Code listings in specifications: if (a && b)if (a &amp;&amp; b)

Worked Example: Escaping a Patent Claim

Suppose you need to include the following claim text in an XML patent specification:

A method for manufacturing a semiconductor device with a bandgap > 2 eV at temperature < 400°C, using Si & Ge alloys.

To make this XML-compliant, you must escape the <, >, and & characters. The > is technically allowed in text but it's safer to escape it to avoid confusion with closing tags. The degree symbol ° can be represented as &#176; or left as-is if the encoding supports it (UTF-8 is recommended).

Correctly escaped version:

<claim>A method for manufacturing a semiconductor device with a bandgap &gt; 2 eV at temperature &lt; 400&#176;C, using Si &amp; Ge alloys.</claim>

If you accidentally write & unescaped, the XML parser will treat &Ge as an entity reference, fail to find it, and throw an error.

Common Pitfalls When Handling Entities in Patent XML

  • Forgetting to escape ampersands in URLs: A reference like http://example.com?foo=1&bar=2 must become http://example.com?foo=1&amp;bar=2.
  • Double-escaping: If you escape an already-escaped entity (e.g., &amp;amp;), the literal text will show &amp; instead of &.
  • Using HTML entities not defined in XML: HTML has many named entities like &nbsp; or &copy; that are not predefined in XML. Use numeric references (&#160;, &#169;) instead.
  • Mixing CDATA and escaping: You can wrap text in <![CDATA[ ... ]]> to avoid escaping, but CDATA sections cannot contain the string ]]> and are not always allowed in patent XML schemas.
  • Encoding mismatches: The XML declaration should specify the encoding (e.g., <?xml version="1.0" encoding="UTF-8"?>) and the file must be saved in that encoding, or characters like ° or © may become garbled.

Using the HTML Entities Tool for Quick Escaping/Unescaping

When preparing patent XML files manually, you can use our HTML entities decoder/encoder to quickly escape or unescape text. Paste your raw claim text, click "Encode", and copy the escaped result. This is especially useful when dealing with large specifications containing many special characters.

FAQ

What is the difference between XML entities and HTML entities?

XML defines only five predefined entities (&lt;, &gt;, &amp;, &quot;, &apos;). HTML defines many more (e.g., &copy;, &reg;). In patent XML, you should use numeric character references for any character not among the five, unless the DTD explicitly defines additional entities.

Can I use CDATA sections to avoid escaping?

Yes, but with caution. CDATA sections allow you to include raw text with <, &, etc., without escaping. However, they cannot contain the string ]]>, and some patent XML schemas may restrict or disallow CDATA in certain elements. Always check the schema documentation.

Why does my patent XML file show "garbled" characters when opened in a browser?

Browsers render XML with syntax highlighting, showing tags in color. This is not garbled—it's the raw XML structure. If you see actual garbage like å¼Â, the file encoding is mismatched (e.g., saved as UTF-8 but declared as ISO-8859-1). Always use UTF-8 encoding.

How do I handle special characters like Greek letters or mathematical symbols?

Use numeric character references. For example, α (Greek alpha) can be written as &#945; or &#x3B1; (hexadecimal). The Unicode code point determines the number.

Is there a tool to validate patent XML files?

Yes, patent offices provide validators. For CNIPA, the "Patent Business Processing System" includes a validation step. You can also use general XML validators like xmllint or online tools, but they may not enforce patent-specific DTD rules.

Conclusion

Properly escaping special characters in XML is a fundamental skill for anyone submitting patent electronic files. By understanding XML entities, avoiding common pitfalls, and using tools like our HTML entities encoder, you can ensure your patent documents are well-formed and accepted by patent offices. Remember: when in doubt, escape the ampersand first—it's the most common culprit behind "XML is garbled" complaints.