Wednesday, October 31, 2012

XML Parser using XmlReader from an XML string in C#

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] pBytes = encoding.GetBytes(strXML);
MemoryStream pMem = new MemoryStream(pBytes, 0, pBytes.Length, true, true);
XmlReader reader = XmlReader.Create(pMem);
string s = Encoding.UTF8.GetString(pMem.GetBuffer(), 0, (int)pMem.Position);
XmlElement element;
XmlDocument xmlDoc = new XmlDocument();
pMem.Seek(0, SeekOrigin.Begin);


while (reader.Read())
{
XmlNode node = null;
switch (reader.NodeType)
{
case XmlNodeType.Element:
bool fEmptyElement = reader.IsEmptyElement;
element = xmlDoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
//element.IsEmpty = fEmptyElement;
//ReadAttributes(reader, element);
//if (!fEmptyElement) {
//parent.AppendChild(element);
//parent = element;
//continue;
//}
//node = element;
break;

case XmlNodeType.EndElement:
//if (parent.ParentNode == null)
//{
// syntax error in document.
// IXmlLineInfo li = (IXmlLineInfo)reader;
// throw new XmlException(string.Format(SR.UnexpectedToken,"", li.LineNumber, li.LinePosition), null, li.LineNumber, li.LinePosition);
// }
//parent = parent.ParentNode;
continue;

case XmlNodeType.EntityReference:
if (reader.CanResolveEntity)
{
reader.ResolveEntity();
}
continue;

case XmlNodeType.EndEntity:
continue;

case XmlNodeType.Attribute:
//node = LoadAttributeNode(parent);
break;

case XmlNodeType.Text:
node = xmlDoc.CreateTextNode(reader.Value);
break;

case XmlNodeType.SignificantWhitespace:
node = xmlDoc.CreateSignificantWhitespace(reader.Value);
break;

case XmlNodeType.Whitespace:
//if (preserveWhitespace) {
// node = xmlDoc.CreateWhitespace(reader.Value);
// break;
//}
//else {
//continue;
//}
continue;
case XmlNodeType.CDATA:
node = xmlDoc.CreateCDataSection(reader.Value);
break;

case XmlNodeType.XmlDeclaration:
break;

case XmlNodeType.ProcessingInstruction:
node = xmlDoc.CreateProcessingInstruction(reader.Name, reader.Value);
break;

case XmlNodeType.Comment:
node = xmlDoc.CreateComment(reader.Value);
break;

case XmlNodeType.DocumentType:
string pubid = r.GetAttribute("PUBLIC");
string sysid = r.GetAttribute("SYSTEM");
node = xmlDoc.CreateDocumentType(reader.Name, pubid, sysid, reader.Value);
break;

default:
//UnexpectedNodeType(reader.NodeType);
break;
}
}

Windows 8 liveblog

http://www.wired.com/gadgetlab/2012/10/liveblog-microsoft-rolls-out-windows-phone-8/

Wednesday, October 17, 2012

How To Prevent Visual Studio 2012 ALL CAPS Menus!

If you can’t stand the ALL CAPS menus in Visual Studio 2012 there’s a way to switch them to normal casing. open your registry editor and create the following registry key and value HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\SuppressUppercaseConversion REG_DWORD value: 1 Go figure why this is set in the registry...
Before


After