BookmarkSubscribeRSS Feed
Yura2301
Quartz | Level 8

Hi all,

Have issue with XML created from SAS , will be appreciate for any help.

So I create XML from SAS using standard libname engine:

filename &filLibName "...temp.xml" ;

      LIBNAME &filLibName XML  XMLTYPE=GENERIC ;

      data &filLibName..TEST_XML;

         set TEST_DATA;

      run;

Then XML goes to validation on java side.For majority of data validation pass ok, without issue,but for some set of data issue occurs, and XML rejects with reason:

An invalid XML character (Unicode: 0x1a) was found in the element content of the document.

It looks like some invalid character come with SAS data and java validation tool reject XML due this character.

XML should be in UNICODE format so I tried to changed libname to :

LIBNAME &filLibName XML  XMLTYPE=GENERIC XMLENCODING='utf8';

And this step changed XML header to:

.<?xml version="1.0" encoding="utf-8" ?>

Some special character occurs before first tag and it again crashed validation on java side, so I changed it in code(just hardcoding), so XML header after this looks like:

<?xml version="1.0" encoding="utf-8" ?>

But the problem still exists, XML message still rejects with same error.

I browsed and found that java developers fixed this issue simply by replacing this char to another allowed character:

http://stackoverflow.com/questions/8505816/streamexception-an-invalid-xml-character-unicode-0x1a

It's also ok for me, but I should realize it on SAS and I actually can't find this character in SAS table,so queston is if there are some smart way to search and replace this symbol in SAS data?

Maybe there are also some way to predict similar issues?I supposed enough should be set option  XMLENCODING='utf8' to libname, but as I experienced it's not enough.

I'm using SAS 9.1.3.

Thanks!

2 REPLIES 2
Tom
Super User Tom
Super User

Since it only happens for some of the data I suspect that the value is actually in the data.

You could try check the character variables in your data sets and eliminate the characters it does not like before writing it to the XML file.

Yura2301
Quartz | Level 8

Hi Tom,

It was my initial idea, but the problem isn't so obvious probably.

I have small SAS table with ~20 rows.

When I send whole this table - issue occurs.

When I eliminate one row - issue doesn't occurs, but then, if I resend this one row - issue also doesn't occurs.

This character probably isn't visible:

http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x

And I can't just visually separate it in data.

I'm actually a little bit confused why the issue is happend and if this spec character at all is in SAS data, maybe it occurs on stage when SAS create XML from SAS table.

I also tried to find this char directly in XML file via n++, but can't see it also.

Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 5928 views
  • 0 likes
  • 2 in conversation