Learn about .NET System.XML and System.Web.Services here...
2009 Mar 26
1 of 224 | How to upgrade Atom 0.3 feeds on the fly with a custom XmlReader for use with WCF Syndication APIs -
Even now that Atom 1.0 has been approved and official for some time, there's a feed every now and then that still uses Atom 0.3 (i.e. Google News! http://news.google.com/?ned=us&topic=w&output=atom).
The .NET APIs for feeds, System.ServiceModel.Syndication, handles RSS 2.0 and Atom 1.0 fine, and you just have to make a single call to load a feed regardless of its format:
SyndicationFeed.Load(xmlReader);
I searched the web looking for an easy answer, but I couldn't find any that would let me seamlessly plug into the .NET APIs to do the feed format upgrade on the fly. So I put one together myself :)
I found Aaron Cope had created XSLT stylesheets to transform Atom 0.3 ......
2009 Mar 18
2 of 224 | Export Your OPML from Outlook - Lately I have fallen in love with Office programming, but I’m still a complete n00b at it. I was pilfering through my RSS feeds the other day, and realized I didn’t have a way to export the feeds list as OPML. Hmm… good time to open Visual Studio and start tinkering. Here is what I came up with. Create the Project To get started, go to the C# node in the New Project window, and you’ll find a sub-node called Office, and another called 2007. Click on the 2007 node, and create a new Outlook 2007 Add-In project (remember that Outlook 2003 didn’t have RSS support out of the box). That creates a project with a file called ThisAddIn.cs. Open that file, and you’l......
2009 Mar 14
3 of 224 | Convert XElement to XmlNode (and Convert XmlNode to XElement) - This is just way cool. Check out Eric White’s blog for a slick use of extension methods to make it easier to convert types in the System.Xml namespace to types in the System.Xml.Linq namespace, and vice-versa. Here’s a quick teaser: XElement e = new XElement("Root",
new XElement("Child",
new XAttribute("Att", "1")
)
);
XmlNode xmlNode = e.GetXmlNode();
Console.WriteLine(xmlNode.OuterXml);
XElement newElement = xmlNode.GetXElement();
Console.WriteLine(newElement);
No, that code won’t compile on its own, you need to define the GetXElement......
2009 Mar 08
4 of 224 | Multiple Form Configurations with ASP.NET Dynamic Data - As some of you know, I enjoy working at high-throughput web applications. One thing I however don't particularily like, is the creation of the necessary backend administration tools. In a lot of the applications I've worked on, data is fed using various XML-ish or proprietary data feeds and is usually 99.9% correct. For the remaining 0.1%, support personell needs some possbility to maintain and change data in every way imaginable. This usually means that it's necessary to create CRUD-style data maintainance applications for dozens or - more likely - hundreds of tables.
As this doesn't really sound like a lot of fun, I had high hopes that ASP.NET Dynamic Data would help our clients a bit......
2009 Mar 06
5 of 224 | MSXML4 SP3 Is Available Now! - Today, we officially released MSXML4.0 Service Pack 3 (SP3) on the Microsoft Download Center as a stand-alone installer in multiple languages.
MSXML4.0 SP3 is a complete replacement of MSXML4.0, MSXML4.0 SP1 and MSXML4.0 SP2 and contains a number of bug fixes to enhance security and reliability.
Approximately nine years ago, MSXML4.0 was released to the web. MSXML4.0 was superseded by MSXML6.0 six+ years ago and is only intended to support legacy applications. After MSXML4.0 SP3, there are no future service packs planned. Also, please note that SP2 support will end in November 2009.
MSXML4.0 customers are recommended to upgrade to MSXML6. MSXML6 has new functiona......
2009 Feb 20
6 of 224 | Ease of Maintenance of LINQ Code - I believe that it is easier to maintain code that is written in the functional style. For one thing, this is the very reason for many of the characteristics of functional code. No state is maintained, so we don’t have to worry about corrupting any state. If a variable is in scope, then the variable has its value, and it will never have another value. And the idea of composability is all about being able to inject/surround/refactor code without making it brittle. In this post, I’m going to show the process of maintaining and modifying a somewhat more involved query.
In a previous post, I wrote a somewhat (although not very) involved query that searched an Open ......
2009 Feb 19
7 of 224 | Read an RSS feed from SSIS - The 3.5 .NET framework introduced a new SyndicationFeed class which simplifies the process of reading (and creating) RSS feeds. To try it out, I threw together a simple SSIS package which reads from an RSS feed using a Script Component. Things to note: I have an Http Connection Manager, but I’m not actually using its connection object in my script. I use it just for its connection string (the URL to the RSS feed) You need to add a reference to System.ServiceModel.Web assembly to access the SyndicationFeed class The Script Task / Script Component will target the 2.0 .NET framework by default. To use the SyndicationFeed class, you’ll need to use the 3.5 .NET framework......
2009 Feb 17
8 of 224 | MSDN Code Gallery Download Report - In an attempt to divert my brain and as a break from SharePoint development, I wrote a simple utility this weekend that generates a consolidated report of download counts for any resource housed at MSDN Code Gallery, including projects, releases, and files. Here is a screenshot: The user interface takes a resource (or project) name and adds it to a list of projects for which the download count report is generated. Using a rich text control, the tool generates a simple report of the downloads for each element. Here is a class diagram which illustrates the basics: I used the Html Agility Pack for scraping the MSDN Code Gallery pages, which is what the tool relies on......
2009 Feb 13
9 of 224 | Undeclared Namespace in XML (eg: xsi is an undeclared namespace) - If you XML source publishes invalid XML for some reason ( i.e. it has Xml elements referring to undeclared namespace ) and you try to load this XML in XMLDocument. You would end up getting exception similar to <NameSpace> is an undeclared namespace.
eg:
<?xml version="1.0" encoding="utf-16"?>
<root>
<Name xsi:nil="true">name1</Name>
<Name xsi:nil="true">name2</Name>
<Name xsi:nil="true">name3</Name>
</root>
Ideally this is an Invalid XML but there is a way to load it in XMLDocument using following code snippet. XmlDocument doc = new XmlDocument();
NameTable nt = new NameTable();
......
2009 Feb 12
10 of 224 | Silverlight Cream for February 12, 2009 -- #515 - In This issue: Jim Lynn, Pencho Popadiyn, Tim Heuer, Scott Guthrie, Mike Snow, Maurice de Beijer, and Dean Chalk.
Shoutouts:
Tim Sneath responds to Adobe's latest salvo: Silverlight is FIZZING, Not Fizzling
Walt Ritscher has Reflecting on Design #9 up, and the 'light graffiti' stuff is pretty cool :)
Azret Botash reports an update on the free Silverlght datagrid from Devexpress: Free Silverlight DataGrid is Fast!
If you think you're up to it, Laurence Moroney says Solve the riddle, and get a free pass to MIX. He's going to list the winner tomorrow and put up another -- give it a shot, and let me know you're going :)
I think I've reported on these before, but Walt Rit......
2009 Jan 26
11 of 224 | Write to the web.config using Linq to Xml - I've seen a couple of implementations of this using the System.Xml namespace from .NET 1.1. Here's a System.Xml.Linq implementation. It would have been nice to make this an extension method:
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table......
2009 Jan 16
12 of 224 | Using LINQ in Excel VSTO with efficient Data Push to Excel Sheet - Wanted to show a simple example to demonstrate, how we could use LINQ in VSTO applications and efficiently populate data into excel. There are two ways you could chose to populate the data into excel based on your requirement.
1. Use Open Xml SDK to open the contents of the file and populate the contents.
2. Use VSTO excel object model to push data into the sheet.
Brief steps to fetch and populate data :
1. Fetch Data from external source.
2. Convert return data to business entities using LINQ.
3. Apply bus......
2008 Dec 19
13 of 224 | Complex class designs begat unintuitive interactions begat unexpected results begat a blog - Frank's question is one any reasonable person could have:So, why is XmlWriter producing a document with encoding = UTF16 when I specify UTF8 ?static void Main(string[] args){ XmlWriterSettings xws = new XmlWriterSettings(); xws.Encoding = Encoding.UTF8; StringBuilder sb = new StringBuilder(); XmlWriter xw = XmlWriter.Create(sb, xws); xw.WriteStartDocument(); xw.WriteElementString("Element", "Value"); xw.WriteEndDocument(); xw.Flush(); xw.Close();}--FrankThat code prodcuces XML with the following preamble:<?xml version="1.0" enco......
2008 Dec 18
14 of 224 | SharePoint 2007 (MOSS/WSS) - Adding header and footer in Word Document (.docx) with ItemAdded Event Receiver using OpenXML - I used OpenXML to add the two metadata column values - document name as the header and modified date as footer while someone upload a document in document library. Please include a reference of WindowsBase and DocumentFormat.OpenXml in the project. WindowsBase is included in .Net framework 3.0/3.5 and you have to download DocumentFormat.OpenXml separately.
Here is the code:
using System;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using System.IO;
using System.IO.Packaging;
using DocumentFormat.OpenXml.Packaging;
using System.Xml;
using System.Collections.Generic;
namespace AddHeaderFooterReceiver
{
&n......
2008 Dec 12
15 of 224 | Modifying Open XML Documents using the SharePoint Object Model - When working with Open XML documents from within SharePoint, you may want to open a specific document, modify it in some way, and then save it, either replacing the original document, or saving to a new location. This isn’t very hard, but there are a few issues. This post describes the issues and presents a minimal amount of code that shows how to open an Open XML document from a SharePoint list, modify it, and then save it back to either the same location, or a different one if you desire.
In detail, the technique consists of:
Writing a function that takes an SPFile as an argument. This SPFile object is the DocumentLibrary list item that we want to modify. ......
2008 Dec 10
16 of 224 | Immutable Collections and Compatibility with Existing Frameworks - When developing my immutable collections library, I spent a lot of time on usability. After all, if a library is not useful then what’s the point? A big portion of usability is being able to work with existing frameworks and technologies. For .Net and collections that means items like Data binding, LINQ etc … Without integrating into popular technologies the usefulness of a particular library is severely impacted and hence usability decreases. Most of the existing collection based infrastructures use the .Net collection interfaces as their form of abstraction. The most straight forward way to ensure compatibility is to implement these interfaces on the collections ......
17 of 224 | Working with In-Memory Open XML Documents -
Sometimes you want to work with Open XML documents in memory. There are two scenarios that I know of:
When working with document libraries in SharePoint, you retrieve a document from the document library as a byte array. You can then modify it as necessary, and then put it back into the document library, either as a new document, or replacing the original.
In a web application, you may want to fabricate Open XML documents on the fly and serve them up to remote users. You don’t want to serialize such temporary documents to the file system. After creating them, you want to send them directly to the end user of the web application.
This blog post presents a b......
2008 Dec 04
18 of 224 | XML Content Parts in the OpenXML SDK DocumentReflector - [Source: http://geekswithblogs.net/EltonStoneman]
The latest release of the OpenXML SDK (v2.0 September 2008 CTP) comes with the DocumentReflector tool which can load an OpenXML document and reverse engineer the code for generating that document with the SDK. It's very handy but there's an issue with it when you have a Word document with content parts that contain XML.
In this scenario, DocumentReflector will build the XML content for the part like this:
public static void GenerateCustomXmlPart1(OpenXmlPart part)
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(part.GetStream());
writer.Write("<?xml version=\"1.0\" encodin......
2008 Nov 28
19 of 224 | Code smell – many usings -
Normal
0
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:" ";
mso-padding-alt:0cm 5.4......
2008 Nov 25
20 of 224 | A DataGrid sample using XML data - I love LINQ, so I'm on a mission to use it in as many samples as possible. This one is pretty trivial but it took me a bit to put together all the pieces of loading up the xml file to getting the binding to recognize the correct attributes. Finally I stylized the DataGrid a bit by using a HeaderStyle.
A few notes:
You need the WPF Toolkit. I'm using Visual Studio 2008 SP1.
Add the WPF Toolkit dlls as resources.
Add the xml file as an embedded resource.
Here's the code:
XAML
<Window x:Class="DataGridXML.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/20......
2008 Nov 15
21 of 224 | Large XML files processing and indexing - Index large XML file for fast access. Use IO and XMLReader for parsing with Regex...
2008 Nov 14
22 of 224 | Getting Document Values from Repeating Nodes in BizTalk - To access a variable in a document in BizTalk is quite easy. First you go to the schema of the document and right click on the value you want to promote. Select Promote -> Show Promotions. To promote the variable as a distinguished property simply click the add button. If you messages are in a separate project make sure you build the solution before continuing. Accessing the promoted property in the orchestration is a simple process. Typing the message name, that represents the schema, in an expression shape. Intellisense will then guide you the rest of the way.
Now try that if the document variable that you require can have multiple values. As soon as you try to promote the field BizTa......
2008 Nov 10
23 of 224 | I Didn't Appreciate that TinyURL had an API - When I created my PowerShell script I opted for SnipUrl as it has a nice API that returns a POX response with your shiny new shortened link (Digsby uses SnipUrl and as I use Digsby for most of my Twittering, most of my URLs are SnipUrls). However, Duncan mentioned he was having trouble accessing my shortened URLs and it was then I discovered that TinyURL has an API that would significantly simplify my PowerShell script. The TinyUrl API looks like this:
http://tinyurl.com/api-create.php?url=http://mikeo.co.uk
and it returns the shortened URL in the response. This means I can do away with my XmlReader and the response parsing code. I also tidied up the SubmitWebRequest function so that the ......
2008 Nov 04
24 of 224 | Remove Rsid Attributes and Elements before Comparing Documents - [Blog Map]
A convenient way to explore Open XML markup is to create a small document, modify the document slightly in the Word user interface, save it, and then compare it with the Open XML Diff utility that comes with the Open XML SDK V2. However, Word adds extraneous elements and attributes that enable merging of two documents that have forked. These elements and attributes show up as changed, and obscure the differences that we’re looking for. An easy way to deal with this is to remove these elements and attributes before comparing documents. We can safely do so without changing the content of the document. This post presents a bit of code that uses t......
2008 Oct 31
25 of 224 | PDC 2008 (10/30) - ???????????????????????8????????????????(???15?)???????????????????? Microsoft .NET Framework: Declarative Programming Using XAML Windows 7 Presentation Vitalization: Graphics Remoting ( RDP) Today and Tomorrow Windows 7: Unlocking the GPU with Direct3D WPF: Extensible BitmapEffects, Pixel Shaders, and WPF Graphics Futures Microsoft .NET Framework: Declarative Programming Using XAMLXAML?????????????XAML?(WF?WCF???)???????????????????????????????????????2????????????? XAML 2009 System.Xaml.dll ? .NET 4.0??? (November 2008 CTP) XAML 2009 XAML 2009 ????????????????? ???????(x:Reference) generics???????(x:TypeArguments) ??????? ?????????? ???(x:Key) ?????????????????? ??????????(x:......
2008 Oct 27
26 of 224 | How to Use altChunk for Document Assembly - [Blog Map]
Merging multiple word processing documents into a single document is something that many people want to do. An application built for attorneys might assemble selected standard clauses into a contract. An application built for book publishers can assemble chapters of a book into a single document. This post explains the semantics of the altChunk element, and provides some code using the Open XML SDK that shows how to use altChunk.
Instead of using altChunk, you could write a program to merge the Open XML markup for documents. You would need to deal with a number of issues, including merging style sheets and resolving conflicting styles, merging the ......
2008 Oct 22
27 of 224 | Writers are like Streams -
I recently saw some application code that misused XmlWriter and which happened not to work all the time as a result. What they were doing was using XmlWriter to write to an underlying stream and then flushing that stream without having flushed the writer.
Depending on the intervening code and the specific document being written in the application code, this might work if all of the content happens to have been committed to the stream prior to it being flushed. It's possible that they picked this error up by copying code from partial samples that don't show what to do with the writer after completing the content.
This example is an extreme demonstration of the problem that should r......
2008 Oct 19
28 of 224 | Creating Data-Bound Content Controls using the Open XML SDK and LINQ to XML - Data-bound content controls are a powerful and convenient way to separate the semantic business data from the markup of an Open XML document. After binding content controls to custom XML, you can query the document for the business data by looking in the custom XML part rather than examining the markup. Querying custom XML is much simpler than querying the document body. However, it’s a little bit involved to create data-bound content controls (but only a little bit). But there is a trick we can do – we can take a document that has un-bound content controls, generate a custom XML part automatically (inferring the elements of the custom XML from the content controls),......
2008 Oct 15
29 of 224 | Open XML SDK 2.0 Architecture - In my first post on the Open XML SDK, I talked about the overall design of the SDK with respect to goals and scenarios. Today, I am going to talk about the architecture of the SDK in terms of its different components.
The SDK Architecture
The Open XML SDK is designed and implemented in a layered approach, starting from a base layer moving towards higher level functionality, such as validation. The following diagram illustrates an overview of the Open XML SDK components.
The System Support layer contains the fundamental components that the SDK is built upon. The Open XML File Format Base Level layer is the core foundation of the SDK. This layer provides you functionality to create Op......
2008 Oct 07
30 of 224 | Mono 2.0 Released - For those Linux devs who don’t have something adamantly against Microsoft, Mono 2.0 has been released! From the release notes: Mono 2.0 is a portable and open source implementation of the .NET framework for Unix, Windows, MacOS and other operating systems. Release Date: October 6th, 2008 Major Highlights Mono 2.0 is a major milestone in the Mono project, and it supports the following features: Microsoft Compatible APIs ADO.NET 2.0 API for accessing databases. ASP.NET 2.0 API for developing Web-based applications. Windows.Forms 2.0 API to create desktop applications. System.XML 2.0: An API to manipulate XML documents. System.Core: Provides support ......
2008 Sep 10
31 of 224 | Frequently Asked Questions on XML in .NET - Part 1 - As part of a separate task, the XML team came up with a list of frequently encountered issues in System.XML; mainly points that we felt were interesting because they were the source of a lot of difficulty for our users. These questions ranged from rarely used (or misused) methods to difficult XML constructs. We focused specifically on scenarios that were particularly difficult to debug. When we had completed the exercise, it occurred to the team that we should publish the list.
So what follows is the first in a multi-part series in which we will outline each of the questions we defined and provide an explanation of the correct usage, along with some sample code. However, our motives ......
32 of 224 | Frequently Asked Questions on XML in .NET - Part 2 - This is the next post in our ongoing FAQ series. See the original post here. Q2: Conformance Level – Fragment There are times when you want to work with a piece of XML that is not a fully conformant xml document; an example of this is when the XML does not have one root element. This type of XML is called an XML fragment. Here is an example of an XML fragment: “<foo></foo><bar></bar>” If this snippet of XML is used as the source for to the XmlReader, the following exception will occur: “There are multiple root elements. Line X, position Y.” This is a good exception message and tells the user exactly what the problem is: more than o......
33 of 224 | OEM Ready Test Case 1 Incorrectly Fails with a UTF-8 manifest - I haven't posted in a while. I've been helping out with a couple other programs we have going on in the labs these days. OEM Ready is a subset of Certified for Windows Vista targeted at applications that ship on new PC's. If you are using the automation in the OEM Ready Certification Test Tool, you can get a false failure if your application has a UTF-8 embedded manifest that has the byte order mark (BOM) included. Visual Studio 2008 includes the BOM if you use it to embed the manifest. The error in the log looks something like this: 2008-09-06T01:56:32.4030000Z Information INFO: Embedded manifest exists: <?xml versi......
2008 Sep 08
34 of 224 | OpenXmlCodeTester: Validating Code in Open XML Documents - Many types of documents contain code, including API documentation, tutorials, specifications, technical books, and magazine articles. Too often, there is no way to automate testing and validation of this code. This post presents a small example program that shows how to use content controls in Open XML word documents to delineate code snippets so that you can automate validation of the snippets.
This scenario was my first use of Open XML – it was the killer application (for me) that prompted me to crack open an Open XML document. I wrote some code to extract the paragraphs that contain code, compile the code, run it, and validate the output. Because I had a system i......
2008 Sep 04
35 of 224 | Implementing a News Aggregator in Silverlight and VB.Net #2 Accessing our database from VB.Net - In the years since the .Net runtime was first released I've seen a number of ways of accessing a SQL database from within VB.Net (or C#). One person I worked with had a nifty utility which would take any database and generate all the code to access it. It has been on my list of jobs to do to implement my own such tool but like other jobs, such as winning the National Lottery or a high stakes poker game. OK the poker game is something my wife will have to do - she is better at poker than me.
What I do have is a class which encapsulates the functions I need to execute stored procedures on the database. All my database access is executed by inheriting from the following class;
Imports Micros......
2008 Sep 02
36 of 224 | How it works: Windows SDK Documentation Part 2 - Many Windows SDK users have questions about the system behind the documentation provided with the SDK. Part 1 of this series explained the basic structure behind the Windows SDK help system. It also looked at how ms-help:// URLs can be used to learn about the organization of the documentation “behind the scenes”. Knowledge of the information in that post is assumed for this post. In this post, the mechanism behind the table of contents (TOC) will be explained. I will include a couple of easy ways to customize the TOC. TOC Manipulation Topics that appear in the documentation all belong to an HXS file. Every HXS file is a compressed collection of topic files ga......
2008 Sep 01
37 of 224 | Duplicate InternalName of the Site column - A duplicate name "<string>" was found. at Microsoft.SharePoint.SPFieldCollection.AddFieldToWeb(String strXml, Boolean checkDisplayName) at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.CreateField(SPWeb web, SerializationInfoHelper infoHelper) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject) at Microsoft.SharePoint.Depl......
2008 Aug 30
38 of 224 | Debugging business logic in AX 2009 SSRS reports - Background
With AX2009 you are now able to do SSRS reports in Visual Studio. The typical process for designing a report consist in creating a query and bind to it, code some business logic (BL) specific to the report and design the visual part.
This post will focus on debugging the report business logic. For more information on designing reports in general, see the msdn documentation
There is also an excellent post on Channel 9 from my friend Manoj here.
Debugging
Let say you've designed a fancy report in VS and in order to make it do cool stuff, you had to write some pretty complex business logic. Unfortunately, your business logic does not do what you think it should be doing. You kn......
2008 Aug 27
39 of 224 | Customizing IntermediateSerializer, part 2 - What can you do when serialization helper properties just aren't enough? Bring out the big guns and write your own ContentTypeSerializer. If you have ever written a ContentTypeWriter or ContentTypeReader, this should seem familiar. To customize the XML serialization for this test class: class TestClass
{
public int elf = 23;
}
We create this helper:
[ContentTypeSerializer]
class TestClassSerializer : ContentTypeSerializer<TestClass>
{
protected override void Serialize(IntermediateWriter output, TestClass value, ContentSerializerAttribute format)
{
int hundreds = value.elf / 100;
int tens......
2008 Aug 20
40 of 224 | XslCompiledTransform.Transform Whitespace - Came across an error when I was using XslCompiledTransfrom. The error is
White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead.
Mmm OK. My VB Code was
xsl.Transform(xmlDoc, xw2)
and I modified it to
xsl.Transform(
The xsl includes the xsl xsl:preserve-space elements="*"/>
<
The white space is not stripped but whatever.
If you googled and found this I hope it helps you out. I wish I had found it hours ago. I like to post things in my blog that take me a while to figure out in the hopes it helps someone else.
New XmlNodeReader(xmlDoc), xw2)
...
2008 Aug 14
41 of 224 | Introducing the XmlPreloadedResolver -
The XmlPreloadedResolver is a new type that we’ve been working on in SilverLight that provides the ability to load a DTD without a call to the network. The new type can act as a manually maintainable cache of DTD’s and XML Streams.
Let’s look at two examples of how the XmlPreloadedResolver can be used.
Example 1:
The XmlPreloadedResolver can be used to pre-load an external DTD. In the following example, a user-defined DTD is pre-loaded into the resolver. The resolver is then used when loading the XML file.
String strDtd = "<!ENTITY entity 'Replacement text'>";
String strXml = @"<!DOCTYPE doc SYSTEM 'myDtd.dtd'>
<doc>&entity;</doc>";
Syste......
2008 Aug 11
42 of 224 | indent xml with .NET -
Original Article:
http://bytes.com/forum/thread176986.html
Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
> to read.[/color]
XmlReader r = new XmlTextReader(new StringReader(myXML));
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
while (r.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
Console.WriteLine(sw.ToString());
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
...
43 of 224 | XmlWriterSettings Encoding Being Ignored? - I had an interesting exchange in an internal mailing list today, and thought that my readers could possibly benefit from this clarification as well. Scenario You are working with the XmlWriter class and trying to write the contents to something. You are expecting the XML declaration to look like:<?xml version="1.0" encoding="utf-8"?>
However, when you inspect the generated XML, it instead looks like:<?xml version="1.0" encoding="utf-16"?>
Background
The XmlWriter method has an overloaded Create method that accepts an XmlWriterSettings object. The XmlWriterSettings allows you to specify if the output XML will be indented, what the indentation character will......
2008 Aug 08
44 of 224 | Parsing/Loading/Searching xml document of size ~ 1GB - The Console application which provide efficent way to parse large xml files using xmlReader and DOM object in hand...
2008 Jul 26
45 of 224 | Consume an RSS Feed with .NET 3.5 - .NET 3.5 added some new classes that really help when dealing with RSS/ATOM feeds. These classes are located in the System.ServiceModel.Syndication namespace in the System.ServiceModel.Web.dll library. The SyndicationFeed class in this namespace can be used to both expose and consume a feed. Today I was attempting to create a clone of my feed on a website that I am toying around with. After doing some research on the System.ServiceModel.Syndication namespace, I found that this is extremely simple to do in 3.5. The following code illustrates just how simple it can be by using the static Load method of SyndicationFeed: 1: // Blog feed
2: Syndicat......
2008 Jun 05
46 of 224 | Setting .NET breakpoints in Windbg for applications that crash on startup - I recently received a question from a reader who wanted to know how to set breakpoints in code for applications that crash on startup. The email went like this: I have a .NET app which is crashing upon startup (it even causes DW20.exe to make an appearance). When I open the .NET app in Windbg, I can see exactly what the exception is and where it happens. What I would like to do is put a breakpoint on the method where the exception is being raised so that I can step through it. This is where I'm stuck. I'm familiar with commands such as !name2ee and !bpmd., however, when I load the .NET app, I don't get a chance to set the breakpoint since the exception happens so early in startup......
2008 Jun 04
47 of 224 | Writing to .Net Config Files - I've been working with config files for quite some time. I was recently reminded that I needed to finish my original article and share my final findings on my personal best practices for working with config files. One of the coolest and most useful features in config files is the file attribute as displayed below (see my other article for a more detailed explaination, preferred-method-for-read-only-config-files). <configuration> <configSections> <section name="MyCustomSection" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </configSections> ......
2008 May 04
48 of 224 | MOSS : How to pass the FBA authenticated user to a PageViewer Web Part? -
f you creates a Form based authenticated site and you were not able to get the authenticated login user token at client site. You can user the following resolution when you are working with PageViwer Web Part.
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;
namespace FBALoginUser
{
[Guid("2ea076de-3536-4d20-b5d2-365dfd098da6")]
public class FBALoginUser : System.Web.UI.WebControls.WebParts.WebPart
{
public FBALogin......
2008 May 03
49 of 224 | A quick walk-through of CLR Integration with SQL Server - This blog post is inspired by a project I've been working on recently. One of the project requirements is writing all the stored procedures and user-defined functions in CLR integration. Although I don't intent to give you the overview of CLR integration in this article, it's not a bad idea to go over the benefits you get from using CLR integration. Stored procedures and user-defined functions/types/aggregates authored in managed code compiles into native code prior to execution, and you can achieve significant performance increases in scenarios where complex computations or business logics are involved. When you create these CLR objects, you can leverage various functions and services CLR ......
2008 Apr 15
50 of 224 | I have a dream! C# Code Completion in Emacs (csense, dabbrev, etc) - No good options here.
I know, dabbrev does some neat things. But it pales in comparison to real code completion as you get in Visual Studio, or, I think, even SharpDevelop.
I checked out a module called csense that a lone developer hacked together last year. The goal of the project looked simple, focused, valuable: real code completion in Emacs for C# !!! Whoohoo!!!!! but
The implementation looks incomplete
There are no docs
I couldn't even figure out how to initially install it
nobody is using it; there were 33 downloads and I think I was about 8 of them.
I couldn't figure out how to configure it or what the various vars did, without wading in knee deep in......