Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: oracle XML to Office

From: "cd~" <ralibey@---------.------>
To: NULL
Date: 2/1/2006 4:25:00 PM
I have run across this alot lately, there is probably a unicode character in 
your document that MSXML is trying to read as ASCII and failing, I have had 
to write a couple different loops to find theses rogue characters.

I just convert the document to a string and iterated through it as a 
character array outputting the character and its code to the trace window, 
any character i found I wrote a replace for then loaded the string into a 
XmlDocument and saved it to the file system. Your invalid character could be 
in either your Xml document or in your Xsl depending on whether or not word 
is trying to load the xsl as well. I would try commenting out the stylesheet 
reference and re-opening it in word or excel, this would at least let you 
know where the invalid character is.

This is the loop that i used to get the string out of a clob in Oracle to 
check the character codes, you will have to modify it to work for your 
situation

decimal testID;

char[] buffer;

long length;



using (OracleDataReader rdr = cmd.ExecuteReader()){

while(rdr.Read()){

testID = rdr.GetDecimal(0);

clob = rdr.GetOracleClobForUpdate(1);

length = clob.Length;

buffer = new char[length];

clob.Read(buffer, 0, (int)length);


List<char> chars = new List<char>(15);


foreach(char c in buffer)

if((int)c > 8000) //this is because i noticed that all the invalid 
characters had a code over 8000, whereas every other character was less than 
255

if(!chars.Contains(c)) chars.Add(c);


foreach(char c in chars){

//Trace.WriteLine(c + ":" + (int)c);

Trace.WriteLine("sXml = sXml.Replace((char)" + (int)c + ", '" + c + "');"); 
//this line outputs the necessary Replace code, which i copied in below, i 
know, its quick and dirty, but it got the job done

}


StringBuilder sb = new StringBuilder((int)length);

sb.Append(buffer, 0, (int)length);

string sXml = sb.ToString();

sXml = sXml.Replace((char)8217, '\'');

sXml = sXml.Replace((char)8220, '\'');

sXml = sXml.Replace((char)8221, '\'');

sXml = sXml.Replace((char)8211, '-');

sXml = sXml.Replace((char)8217, '\'');

sXml = sXml.Replace((char)8220, '\'');

sXml = sXml.Replace((char)8221, '\'');

sXml = sXml.Replace((char)8211, '-');

sXml = sXml.Replace((char)0, ' ');

sXml.Trim();


xml.LoadXml(sXml);

xml.Save(@"c:\" + testID + ".xml");


clob.Erase();

buffer = sXml.ToCharArray();

clob.Write(buffer, 0, buffer.Length);


}

}

This isn't the most pretty solution, but it worked for me.

-R

<oaksong@h...> wrote in message 
news:1138824183.656699.146540@g......
> I'm exporting an XML file from Oracle. It's a simple grid. I can open
> it just fine with Internet Explorer. I have Office 2003 and I've got
> the XML toolbox for Excel. I've tried to open the XML file with both
> Word and Excel and both of them refuse to properly open the file.
>
> Here's the file:
>
> output.xml
> <?xml version = "1.0" ?>
> <?xml:stylesheet type="text/xsl" href="item_category.xsl"?>
> <!DOCTYPE GRID [
>  <!ELEMENT GRID (BANDS, COLUMNS, ROWS*)>
>  <!ATTLIST GRID ExportVersion CDATA #REQUIRED>
>  <!ELEMENT BANDS (BAND*)>
>  <!ELEMENT BAND EMPTY>
>  <!ATTLIST BAND Index CDATA #REQUIRED>
>  <!ATTLIST BAND Caption CDATA #IMPLIED>
>  <!ELEMENT COLUMNS (COLUMN*)>
>  <!ELEMENT COLUMN EMPTY>
>  <!ATTLIST COLUMN Name CDATA #REQUIRED>
>  <!ATTLIST COLUMN Caption CDATA #IMPLIED>
>  <!ATTLIST COLUMN Index CDATA #REQUIRED>
>  <!ATTLIST COLUMN BandIndex CDATA #REQUIRED>
>  <!ATTLIST COLUMN RowIndex CDATA #REQUIRED>
>  <!ATTLIST COLUMN ColIndex CDATA #REQUIRED>
>  <!ATTLIST COLUMN Width CDATA #IMPLIED>
>  <!ELEMENT GROUP (GROUP*, ROW*)>
>  <!ATTLIST GROUP GroupText CDATA #IMPLIED>
>  <!ELEMENT ROWS (ROW*)>
>  <!ELEMENT ROW EMPTY>
>  <!ATTLIST ROW dbGridColumn4 CDATA #IMPLIED>
>  <!ATTLIST ROW dbGridColumn5 CDATA #IMPLIED>
> ]>
> <GRID ExportVersion="1.0">
>  <BANDS>
>    <BAND Index="0" Caption=""></BAND>
>  </BANDS>
>  <COLUMNS>
>    <COLUMN Name="dbGridColumn4" Caption="ITEM_CAT_ID" Index="3"
> BandIndex="0" RowIndex="0" ColIndex="0" Width="98"></COLUMN>
>    <COLUMN Name="dbGridColumn5" Caption="ITEM_CAT_DESC" Index="4"
> BandIndex="0" RowIndex="0" ColIndex="1" Width="168"></COLUMN>
>  </COLUMNS>
>  <ROWS>
>    <ROW dbGridColumn4="1" dbGridColumn5="FIRE ARM"></ROW>
>    <ROW dbGridColumn4="2" dbGridColumn5="NON LEATHAL WEAPON"></ROW>
>    <ROW dbGridColumn4="3" dbGridColumn5="FURNITURE"></ROW>
>    <ROW dbGridColumn4="5" dbGridColumn5="ACCESSORIES"></ROW>
>    <ROW dbGridColumn4="6" dbGridColumn5="COMPUTER"></ROW>
>    <ROW dbGridColumn4="7" dbGridColumn5="AMMUNITION"></ROW>
>    <ROW dbGridColumn4="8" dbGridColumn5="BADGE"></ROW>
>    <ROW dbGridColumn4="9" dbGridColumn5="HAND CUFFS"></ROW>
>    <ROW dbGridColumn4="10" dbGridColumn5="BATTON"></ROW>
>    <ROW dbGridColumn4="11" dbGridColumn5="HAND RADIO"></ROW>
>  </ROWS>
> </GRID>
>
> Word says there's a "bad character".
>
> Any suggestions.
>
> PS: Isn't XML supposed to behave according to "standards"?
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent