0

I want a fool proof way to catch all invalid XML chars from an XML string. sol, far I couldn't find any that catches all the invalid chars in XML. I am using .Net 4.0 and here is my string.

string abc = @"<Attribute key=""History"" value="" ....................................................&#x0A;3/4/2016 7:09:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: created/confirmed datasheet &amp; parameters in library datasheet folder &#x0D;&#x0A;\share1\PLATFORM_DESIGN\Hardware_Design\Library_Datasheets\ic\REQ42373&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:39:27 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: READY FOR MFG ENG review&#x0D;&#x0A;&#x0D;&#x0A;PASED LIBRARY review&#x0D;&#x0A;deleted un-used PROPERTIES (CLIP_DRAWING)&#x0D;&#x0A;confirmed DFA_DEV_CLASS = SUB50&#x0D;&#x0A;PHYSICAL checked: &#x0D;&#x0A;confirmed DRAWING LOCKED = TRUE&#x0D;&#x0A;Is the body size at least as big as the maximum body size on the datasheet? yes  (2.9x3.15)&#x0D;&#x0A;Are the pins numbered correctly according to the datasheet? yes &#x0D;&#x0A;Is the pitch of the symbol the same as the pitch of the part ? yes  (datasheet = 0.65)&#x0D;&#x0A;Is the width of the pad at least the same width of the max lead? yes &#x0D;&#x0A;Is pin 1 identified in silkscreen? yes  (circles, plus assembly top circle)&#x0D;&#x0A;Is there a placebound top shape extending .1MM from body edge? yes &#x0D;&#x0A;Is the height correctly indicated in the placebound top shape? yes  1.3mm&#x0D;&#x0A;Is the ref des correct for symbol type (parts with center die pad use EU)? yes -- U* &#x0D;&#x0A;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins? yes &#x0D;&#x0A;Does the symbol have a DFA_Class assigned? yes-- DFA_DEV_CLASS = SUB50 &#x0D;&#x0A;Pitch &lt;50 mils &#x0D;&#x0A;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils? &#x0D;&#x0A;4.25mm + 1.27 (50 mil) = 5.52mmm --- 5.53 on symbol &#x0D;&#x0A;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils? &#x0D;&#x0A;Heel-to-heel 1.788 (70 mil) or 2.446 (98mil) compared to 2.285mm (90mil) on symbol &#x0D;&#x0A;Has the lock property been applied to the symbol? yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:17:09 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: added SUBCLASS &quot;lib_rev&quot; , added text REV1&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:16:19 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: PHYSICAL: missing LIB_REV subclass&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:10:56 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: Schematic symbol: &#x0D;&#x0A;Does the symbol pinout match package specified by DE?  yes (DCT package for SSOP)&#x0D;&#x0A;Is the correct IPN/REQ# for the part in the part properties? Yes  (PTF entry: placeholder REQ42373)&#x0D;&#x0A;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?  yes (known exception: no BOM, LEAD FREE, FINANCE property)&#x0D;&#x0A;Do all the properties in the symbol match the datasheet and/or SPEED? yes: match datasheet (DCT package for SSOP) &#x0D;&#x0A;Is the ref des correct for the part type?  yes: U* &#x0D;&#x0A;Is the correct mechanical symbol in PTF entry? yes: PTF entry w\new PHYSICAL: sSOP8_P65MM_2P8X2P95_1P3H&#x0D;&#x0A;Has the pin organization been okayed by the DE?  yes: matches typical in datasheet &#x0D;&#x0A;Are all the pins on grid? yes &#x0D;&#x0A;Does the symbol package? yes: packaged successfully &#x0D;&#x0A;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?) &#x0D;&#x0A;peer reviewed  &#x0D;&#x0A;&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:55:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: peer review:&#x0D;&#x0A;LOGICAL : removed V from pin text (inside body) for NC pin 7&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:54:07 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (DE Review)&#x0A;Description: placeholder Part Number&#x0D;&#x0A;verbal approval by Jim Yoder for LOGICAL symbol&#x0D;&#x0A;&#x01; &#x02;&#x11;&#x12;&#x01; &#x04;&#x09;&#x04;&#x0B;&#x13;&#x0D;&#x0A; &#x02;&#x14;&#x08;&#x01;&#x0E;&#x0F;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 11:11:03 AM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Pending Validation) (Stakeholder(s) Review)&#x0A;Description: Ready for DE, ME and Peer review.&#x0D;&#x0A;Schematic symbol:&#x0D;&#x0A;1&#x09;Does the symbol pinout match package specified by DE?&#x09;Yes&#x0D;&#x0A;2&#x09;Is the correct IPN/REQ# for the part in the part properties?&#x09;Yes&#x0D;&#x0A;3&#x09;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?&#x09;Yes&#x0D;&#x0A;4&#x09;Do all the properties in the symbol match the datasheet and/or SPEED?&#x09;Yes&#x0D;&#x0A;5&#x09;Is the ref des correct for the part type?&#x09;Yes&#x0D;&#x0A;6&#x09;Is the correct mechanical symbol in the package properties?&#x09;Yes&#x0D;&#x0A;7&#x09;Has the pin organization been okayed by the DE?&#x09;No&#x0D;&#x0A;8&#x09;Are all the pins on grid?&#x09;Yes&#x0D;&#x0A;9&#x09;Does the symbol package?&#x09;Yes&#x0D;&#x0A;10&#x09;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?)&#x09;No&#x0D;&#x0A;Footprint:&#x0D;&#x0A;1&#x09;Is the body size at least as big as the maximum body size on the datasheet?&#x09;Yes&#x0D;&#x0A;2&#x09;Are the pins numbered correctly according to the datasheet?&#x09;Yes&#x0D;&#x0A;3&#x09;Is the pitch of the symbol the same as the pitch of the part?&#x09;Yes&#x0D;&#x0A;4&#x09;Is the width of the pad at least the same width of the max lead?&#x09;Yes&#x0D;&#x0A;5&#x09;Is pin 1 identified in silkscreen?&#x09;Yes&#x0D;&#x0A;6&#x09;Is there a placebound top shape extending .1MM from body edge?&#x09;Yes&#x0D;&#x0A;7&#x09;Is the height correctly indicated in the placebound top shape?&#x09;&#x0D;&#x0A;8&#x09;Is the ref des correct for symbol type (parts with center die pad use EU)?&#x09;Yes&#x0D;&#x0A;9&#x09;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins?&#x09;Yes&#x0D;&#x0A;10&#x09;Does the symbol have a DFA_Class assigned?&#x09;Yes&#x0D;&#x0A;11&#x09;Pitch &lt;50 mils&#x09;Yes&#x0D;&#x0A;12&#x09;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;13&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;15&#x09;Pitch &gt;50 mils&#x09;N/A&#x0D;&#x0A;16&#x09;Is the symbol toe to toe at least 30 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;17&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;19&#x09;Pitch with &lt;.165 MM airgap&#x09;N/A&#x0D;&#x0A;20&#x09;Is there soldermask clearance equaling metal pattern plus gaps between adjacent pads?&#x09;N/A&#x0D;&#x0A;21&#x09;Is there route keepout top where there is soldermask clearance between adjacent pins?&#x09;N/A&#x0D;&#x0A;22&#x09;Has the lock property been applied to the symbol?&#x09;Yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:50:51 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: Names added for Schematic symbol and Footprint.&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:39:32 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: In Process of creation.&#x0A;&#x0A;&#x0A;....................................................&#x0A;2/22/2016 3:55:00 PM U.S. AZ (UTC/GMT -7), YODER, JIM :  (New) (New)&#x0A;Description: new symbols&#x0A;&#x0A;Attached file: TI ts5a2053""/>";

I am using the following code

    var xmlPattern = "[^\u0001-\uD7FF\uE000-\uFFFD\ud800\udc00-\udbff\udfff]";

var newXml = xml.replace(new RegExp(xmlPattern , "g"), "");

but it doesn't catch &#x01; &#x02;

I checked here,here but none helped. Edit:- Here is the complete Program

    using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Globalization;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
using System.Net;

class Program
{

    static void Main()
    {
        string abc = @"<Attribute key=""History"" value="" ....................................................&#x0A;3/4/2016 7:09:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: created/confirmed datasheet &amp; parameters in library datasheet folder &#x0D;&#x0A;\share1\PLATFORM_DESIGN\Hardware_Design\Library_Datasheets\ic\REQ42373&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:39:27 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: READY FOR MFG ENG review&#x0D;&#x0A;&#x0D;&#x0A;PASED LIBRARY review&#x0D;&#x0A;deleted un-used PROPERTIES (CLIP_DRAWING)&#x0D;&#x0A;confirmed DFA_DEV_CLASS = SUB50&#x0D;&#x0A;PHYSICAL checked: &#x0D;&#x0A;confirmed DRAWING LOCKED = TRUE&#x0D;&#x0A;Is the body size at least as big as the maximum body size on the datasheet? yes  (2.9x3.15)&#x0D;&#x0A;Are the pins numbered correctly according to the datasheet? yes &#x0D;&#x0A;Is the pitch of the symbol the same as the pitch of the part ? yes  (datasheet = 0.65)&#x0D;&#x0A;Is the width of the pad at least the same width of the max lead? yes &#x0D;&#x0A;Is pin 1 identified in silkscreen? yes  (circles, plus assembly top circle)&#x0D;&#x0A;Is there a placebound top shape extending .1MM from body edge? yes &#x0D;&#x0A;Is the height correctly indicated in the placebound top shape? yes  1.3mm&#x0D;&#x0A;Is the ref des correct for symbol type (parts with center die pad use EU)? yes -- U* &#x0D;&#x0A;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins? yes &#x0D;&#x0A;Does the symbol have a DFA_Class assigned? yes-- DFA_DEV_CLASS = SUB50 &#x0D;&#x0A;Pitch &lt;50 mils &#x0D;&#x0A;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils? &#x0D;&#x0A;4.25mm + 1.27 (50 mil) = 5.52mmm --- 5.53 on symbol &#x0D;&#x0A;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils? &#x0D;&#x0A;Heel-to-heel 1.788 (70 mil) or 2.446 (98mil) compared to 2.285mm (90mil) on symbol &#x0D;&#x0A;Has the lock property been applied to the symbol? yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:17:09 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: added SUBCLASS &quot;lib_rev&quot; , added text REV1&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:16:19 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: PHYSICAL: missing LIB_REV subclass&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:10:56 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: Schematic symbol: &#x0D;&#x0A;Does the symbol pinout match package specified by DE?  yes (DCT package for SSOP)&#x0D;&#x0A;Is the correct IPN/REQ# for the part in the part properties? Yes  (PTF entry: placeholder REQ42373)&#x0D;&#x0A;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?  yes (known exception: no BOM, LEAD FREE, FINANCE property)&#x0D;&#x0A;Do all the properties in the symbol match the datasheet and/or SPEED? yes: match datasheet (DCT package for SSOP) &#x0D;&#x0A;Is the ref des correct for the part type?  yes: U* &#x0D;&#x0A;Is the correct mechanical symbol in PTF entry? yes: PTF entry w\new PHYSICAL: sSOP8_P65MM_2P8X2P95_1P3H&#x0D;&#x0A;Has the pin organization been okayed by the DE?  yes: matches typical in datasheet &#x0D;&#x0A;Are all the pins on grid? yes &#x0D;&#x0A;Does the symbol package? yes: packaged successfully &#x0D;&#x0A;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?) &#x0D;&#x0A;peer reviewed  &#x0D;&#x0A;&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:55:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: peer review:&#x0D;&#x0A;LOGICAL : removed V from pin text (inside body) for NC pin 7&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:54:07 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (DE Review)&#x0A;Description: placeholder Part Number&#x0D;&#x0A;verbal approval by Jim Yoder for LOGICAL symbol&#x0D;&#x0A;&#x01; &#x02;&#x11;&#x12;&#x01; &#x04;&#x09;&#x04;&#x0B;&#x13;&#x0D;&#x0A; &#x02;&#x14;&#x08;&#x01;&#x0E;&#x0F;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 11:11:03 AM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Pending Validation) (Stakeholder(s) Review)&#x0A;Description: Ready for DE, ME and Peer review.&#x0D;&#x0A;Schematic symbol:&#x0D;&#x0A;1&#x09;Does the symbol pinout match package specified by DE?&#x09;Yes&#x0D;&#x0A;2&#x09;Is the correct IPN/REQ# for the part in the part properties?&#x09;Yes&#x0D;&#x0A;3&#x09;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?&#x09;Yes&#x0D;&#x0A;4&#x09;Do all the properties in the symbol match the datasheet and/or SPEED?&#x09;Yes&#x0D;&#x0A;5&#x09;Is the ref des correct for the part type?&#x09;Yes&#x0D;&#x0A;6&#x09;Is the correct mechanical symbol in the package properties?&#x09;Yes&#x0D;&#x0A;7&#x09;Has the pin organization been okayed by the DE?&#x09;No&#x0D;&#x0A;8&#x09;Are all the pins on grid?&#x09;Yes&#x0D;&#x0A;9&#x09;Does the symbol package?&#x09;Yes&#x0D;&#x0A;10&#x09;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?)&#x09;No&#x0D;&#x0A;Footprint:&#x0D;&#x0A;1&#x09;Is the body size at least as big as the maximum body size on the datasheet?&#x09;Yes&#x0D;&#x0A;2&#x09;Are the pins numbered correctly according to the datasheet?&#x09;Yes&#x0D;&#x0A;3&#x09;Is the pitch of the symbol the same as the pitch of the part?&#x09;Yes&#x0D;&#x0A;4&#x09;Is the width of the pad at least the same width of the max lead?&#x09;Yes&#x0D;&#x0A;5&#x09;Is pin 1 identified in silkscreen?&#x09;Yes&#x0D;&#x0A;6&#x09;Is there a placebound top shape extending .1MM from body edge?&#x09;Yes&#x0D;&#x0A;7&#x09;Is the height correctly indicated in the placebound top shape?&#x09;&#x0D;&#x0A;8&#x09;Is the ref des correct for symbol type (parts with center die pad use EU)?&#x09;Yes&#x0D;&#x0A;9&#x09;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins?&#x09;Yes&#x0D;&#x0A;10&#x09;Does the symbol have a DFA_Class assigned?&#x09;Yes&#x0D;&#x0A;11&#x09;Pitch &lt;50 mils&#x09;Yes&#x0D;&#x0A;12&#x09;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;13&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;15&#x09;Pitch &gt;50 mils&#x09;N/A&#x0D;&#x0A;16&#x09;Is the symbol toe to toe at least 30 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;17&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;19&#x09;Pitch with &lt;.165 MM airgap&#x09;N/A&#x0D;&#x0A;20&#x09;Is there soldermask clearance equaling metal pattern plus gaps between adjacent pads?&#x09;N/A&#x0D;&#x0A;21&#x09;Is there route keepout top where there is soldermask clearance between adjacent pins?&#x09;N/A&#x0D;&#x0A;22&#x09;Has the lock property been applied to the symbol?&#x09;Yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:50:51 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: Names added for Schematic symbol and Footprint.&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:39:32 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: In Process of creation.&#x0A;&#x0A;&#x0A;....................................................&#x0A;2/22/2016 3:55:00 PM U.S. AZ (UTC/GMT -7), YODER, JIM :  (New) (New)&#x0A;Description: new symbols&#x0A;&#x0A;Attached file: TI ts5a2053""/>";
        CleanInvalidXmlChars(abc);
        Console.WriteLine(XElement.Parse(abc));

    }
    public static string CleanInvalidXmlChars(string text)   
 {   
   string Pattern=@"#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|7F|8[0-46-9A-F]9[0-9A-F])";
   string newString = string.Empty;
   Regex regex = new Regex(Pattern, RegexOptions.IgnoreCase);
   if (regex.IsMatch(text))
        newString=regex.Replace(text, "");   

     return newString.ToString();

 }  
}
Programmerzzz
  • 1,237
  • 21
  • 48
  • Possible duplicate of [Escape invalid XML characters in C#](http://stackoverflow.com/questions/8331119/escape-invalid-xml-characters-in-c-sharp) – Ondrej Svejdar Mar 07 '16 at 20:05
  • @SLaks: what do you mean by its not C# code? – Programmerzzz Mar 07 '16 at 20:08
  • `.replace(new RegExp(` is Javascript. – SLaks Mar 07 '16 at 20:15
  • Ohh...I see what you say, Now I posted the full C# code....@SLaks, thanks for pointing out. – Programmerzzz Mar 07 '16 at 20:16
  • Also, `#x...` is not invalid. What problem are you trying to solve? – SLaks Mar 07 '16 at 20:16
  • So, The bigger pic is, I retrieve string `abc` from DB .when I try to load using XML.Parse, it throws error and on careful examination of the string, I found that there are some invalid chars like `` etc.. Thus I wish to eliminate thos einvalid chars before I call my `XElement.Parse(abc)` and display this value on the Page. hope I could make more sense now – Programmerzzz Mar 07 '16 at 20:20

2 Answers2

0

Dont replace them - allow them by using a CDATA-Section CDATA-Section MSDN

Cadburry
  • 1,844
  • 10
  • 21
0

For starters, note that your function CleanInvalidXmlChars() returns a new string but you're not doing anything with this string. Also xml version might be 1.1 so it requires a different character filter. Please try this code...

static void Main()
{
    string abc = @"<Attribute key=""History"" value="" ....................................................&#x0A;3/4/2016 7:09:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: created/confirmed datasheet &amp; parameters in library datasheet folder &#x0D;&#x0A;\share1\PLATFORM_DESIGN\Hardware_Design\Library_Datasheets\ic\REQ42373&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:39:27 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (ME Review)&#x0A;Description: READY FOR MFG ENG review&#x0D;&#x0A;&#x0D;&#x0A;PASED LIBRARY review&#x0D;&#x0A;deleted un-used PROPERTIES (CLIP_DRAWING)&#x0D;&#x0A;confirmed DFA_DEV_CLASS = SUB50&#x0D;&#x0A;PHYSICAL checked: &#x0D;&#x0A;confirmed DRAWING LOCKED = TRUE&#x0D;&#x0A;Is the body size at least as big as the maximum body size on the datasheet? yes  (2.9x3.15)&#x0D;&#x0A;Are the pins numbered correctly according to the datasheet? yes &#x0D;&#x0A;Is the pitch of the symbol the same as the pitch of the part ? yes  (datasheet = 0.65)&#x0D;&#x0A;Is the width of the pad at least the same width of the max lead? yes &#x0D;&#x0A;Is pin 1 identified in silkscreen? yes  (circles, plus assembly top circle)&#x0D;&#x0A;Is there a placebound top shape extending .1MM from body edge? yes &#x0D;&#x0A;Is the height correctly indicated in the placebound top shape? yes  1.3mm&#x0D;&#x0A;Is the ref des correct for symbol type (parts with center die pad use EU)? yes -- U* &#x0D;&#x0A;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins? yes &#x0D;&#x0A;Does the symbol have a DFA_Class assigned? yes-- DFA_DEV_CLASS = SUB50 &#x0D;&#x0A;Pitch &lt;50 mils &#x0D;&#x0A;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils? &#x0D;&#x0A;4.25mm + 1.27 (50 mil) = 5.52mmm --- 5.53 on symbol &#x0D;&#x0A;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils? &#x0D;&#x0A;Heel-to-heel 1.788 (70 mil) or 2.446 (98mil) compared to 2.285mm (90mil) on symbol &#x0D;&#x0A;Has the lock property been applied to the symbol? yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:17:09 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: added SUBCLASS &quot;lib_rev&quot; , added text REV1&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:16:19 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: PHYSICAL: missing LIB_REV subclass&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 6:10:56 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: Schematic symbol: &#x0D;&#x0A;Does the symbol pinout match package specified by DE?  yes (DCT package for SSOP)&#x0D;&#x0A;Is the correct IPN/REQ# for the part in the part properties? Yes  (PTF entry: placeholder REQ42373)&#x0D;&#x0A;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?  yes (known exception: no BOM, LEAD FREE, FINANCE property)&#x0D;&#x0A;Do all the properties in the symbol match the datasheet and/or SPEED? yes: match datasheet (DCT package for SSOP) &#x0D;&#x0A;Is the ref des correct for the part type?  yes: U* &#x0D;&#x0A;Is the correct mechanical symbol in PTF entry? yes: PTF entry w\new PHYSICAL: sSOP8_P65MM_2P8X2P95_1P3H&#x0D;&#x0A;Has the pin organization been okayed by the DE?  yes: matches typical in datasheet &#x0D;&#x0A;Are all the pins on grid? yes &#x0D;&#x0A;Does the symbol package? yes: packaged successfully &#x0D;&#x0A;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?) &#x0D;&#x0A;peer reviewed  &#x0D;&#x0A;&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:55:29 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (Library Review)&#x0A;Description: peer review:&#x0D;&#x0A;LOGICAL : removed V from pin text (inside body) for NC pin 7&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 4:54:07 PM U.S. AZ (UTC/GMT -7), MEADORS, CY I:  (Pending Validation) (DE Review)&#x0A;Description: placeholder Part Number&#x0D;&#x0A;verbal approval by Jim Yoder for LOGICAL symbol&#x0D;&#x0A;&#x01; &#x02;&#x11;&#x12;&#x01; &#x04;&#x09;&#x04;&#x0B;&#x13;&#x0D;&#x0A; &#x02;&#x14;&#x08;&#x01;&#x0E;&#x0F;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/4/2016 11:11:03 AM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Pending Validation) (Stakeholder(s) Review)&#x0A;Description: Ready for DE, ME and Peer review.&#x0D;&#x0A;Schematic symbol:&#x0D;&#x0A;1&#x09;Does the symbol pinout match package specified by DE?&#x09;Yes&#x0D;&#x0A;2&#x09;Is the correct IPN/REQ# for the part in the part properties?&#x09;Yes&#x0D;&#x0A;3&#x09;Does the symbol have BOM, Device, Finance, IPN, Lead Free, MFR, MFR P/N, PART_NUMBER, ROOM and NO_STUFF properties in the part properties?&#x09;Yes&#x0D;&#x0A;4&#x09;Do all the properties in the symbol match the datasheet and/or SPEED?&#x09;Yes&#x0D;&#x0A;5&#x09;Is the ref des correct for the part type?&#x09;Yes&#x0D;&#x0A;6&#x09;Is the correct mechanical symbol in the package properties?&#x09;Yes&#x0D;&#x0A;7&#x09;Has the pin organization been okayed by the DE?&#x09;No&#x0D;&#x0A;8&#x09;Are all the pins on grid?&#x09;Yes&#x0D;&#x0A;9&#x09;Does the symbol package?&#x09;Yes&#x0D;&#x0A;10&#x09;Has the symbol been double-checked after a 24hr waiting period? (Or a second person double-checked the symbol?)&#x09;No&#x0D;&#x0A;Footprint:&#x0D;&#x0A;1&#x09;Is the body size at least as big as the maximum body size on the datasheet?&#x09;Yes&#x0D;&#x0A;2&#x09;Are the pins numbered correctly according to the datasheet?&#x09;Yes&#x0D;&#x0A;3&#x09;Is the pitch of the symbol the same as the pitch of the part?&#x09;Yes&#x0D;&#x0A;4&#x09;Is the width of the pad at least the same width of the max lead?&#x09;Yes&#x0D;&#x0A;5&#x09;Is pin 1 identified in silkscreen?&#x09;Yes&#x0D;&#x0A;6&#x09;Is there a placebound top shape extending .1MM from body edge?&#x09;Yes&#x0D;&#x0A;7&#x09;Is the height correctly indicated in the placebound top shape?&#x09;&#x0D;&#x0A;8&#x09;Is the ref des correct for symbol type (parts with center die pad use EU)?&#x09;Yes&#x0D;&#x0A;9&#x09;Is there a solid shape matching body outline in Package_Geometry, Dfa_Bound_Top, plus pins?&#x09;Yes&#x0D;&#x0A;10&#x09;Does the symbol have a DFA_Class assigned?&#x09;Yes&#x0D;&#x0A;11&#x09;Pitch &lt;50 mils&#x09;Yes&#x0D;&#x0A;12&#x09;Is the symbol toe to toe at least 50 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;13&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;Yes&#x0D;&#x0A;15&#x09;Pitch &gt;50 mils&#x09;N/A&#x0D;&#x0A;16&#x09;Is the symbol toe to toe at least 30 mils greater than the part toe to toe rounded to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;17&#x09;Is the symbol heel to heel at least 30 mils less than the part heel to heel or 10 mils less than part min body (whichever is greater) rounded down to the nearest 10 mils?&#x09;N/A&#x0D;&#x0A;19&#x09;Pitch with &lt;.165 MM airgap&#x09;N/A&#x0D;&#x0A;20&#x09;Is there soldermask clearance equaling metal pattern plus gaps between adjacent pads?&#x09;N/A&#x0D;&#x0A;21&#x09;Is there route keepout top where there is soldermask clearance between adjacent pins?&#x09;N/A&#x0D;&#x0A;22&#x09;Has the lock property been applied to the symbol?&#x09;Yes&#x0D;&#x0A;&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:50:51 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: Names added for Schematic symbol and Footprint.&#x0A;&#x0A;&#x0A;....................................................&#x0A;3/2/2016 5:39:32 PM U.S. AZ (UTC/GMT -7), MAGALLANES, J. L:  (Active) (In Process)&#x0A;Description: In Process of creation.&#x0A;&#x0A;&#x0A;....................................................&#x0A;2/22/2016 3:55:00 PM U.S. AZ (UTC/GMT -7), YODER, JIM :  (New) (New)&#x0A;Description: new symbols&#x0A;&#x0A;Attached file: TI ts5a2053""/>";
    XElement xml = ParseXml(abc);
    Console.WriteLine(xml);
}
private static XElement ParseXml(string text)
{
    XElement xml = null;
    try
    {
        xml = ParseXml(text, 1.0f);
    }
    catch(Exception)
    {
        xml = ParseXml(text, 1.1f);
    }
    return xml;
}

private static XElement ParseXml(string text, float xmlVersion)
{
    string newString = CleanInvalidXmlChars(text, xmlVersion);
    return XElement.Parse(newString);
}

private static string CleanInvalidXmlChars(string text, float xmlVersion)
{
    const string patternVersion1_0 = @"&#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|7F|8[0-46-9A-F]9[0-9A-F]);";
    const string patternVersion1_1 = @"&#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|[19][0-9A-F]|7F|8[0-46-9A-F]|0?[1-8BCEF]);";
    string Pattern = xmlVersion == 1.0f ? patternVersion1_0 : patternVersion1_1;
    string newString = string.Empty;
    Regex regex = new Regex(Pattern, RegexOptions.IgnoreCase);
    if (regex.IsMatch(text))
        newString = regex.Replace(text, "");
    else
        newString = text;

    return newString.ToString();

}
derloopkat
  • 6,232
  • 16
  • 38
  • 45
  • Yes, this xml is a part of a much larger XML , hence I used it as a test case for this. However, the original XML file has a root. Moreover, the applicatoin doesn't error out saying that it didn't find root element – Programmerzzz Mar 07 '16 at 20:53
  • I believe your xml version might be 1.1 instead 1.0, so it requires a different regex. I have posted my code. – derloopkat Mar 07 '16 at 21:15
  • I retrieve the string abc from DB where the column type is XML. So, not really sure if XML version is 1.0 or 1.1. But I found many resources in internet saying upgrading to XML 1.1 just to accept the invalid XML chars in 1.0 is not recommended. Thus I closed that option – Programmerzzz Mar 07 '16 at 21:32
  • BTW..How do we know if Database XML column generates a Version 1.0 XML or Version 1.1 XML? – Programmerzzz Mar 07 '16 at 21:39
  • Because currently there are only two versions in use. That's why the code I've posted above worked. – derloopkat Mar 07 '16 at 22:16
  • Yes, So...Can we conclude that DB column is generating XML 1.1 ? If so, there should be an Option that we could control the version of XML generated, if we provide a target version,it gets generated else use latest version. Any idea in those directions? – Programmerzzz Mar 07 '16 at 22:24
  • Pass the version as parameter to the console application. – derloopkat Mar 07 '16 at 22:35
  • This is part of a bigger XMl from DB which is out of my control. it can be 1,1.1 or any other version in future. Any foolproof way to ientify version from XML itself? – Programmerzzz Mar 07 '16 at 22:41
  • If you have the entire original xml, look for the version number e.g. . If you don't have this tag then try 1.0 in your code, if fails then try 1.1. In C# it can be done by using a Try/Catch block. – derloopkat Mar 07 '16 at 23:01