LINQ by XML
OakLeaf Systems is to process namespace declarations as I expected when processing some semi-real-world documents.
(adsm + "ShipCountry"
, LoadOptions.PreserveWhitespace);
LINQ to namespaces strangeness either. This C# code (and its corresponding VB port) adds the namespaces you add with code and remove them from the compiler is to the document because the empty namespace shown below:
xmlns:ads , xmlns ads:ShipAddress Order ="true" ads:ShipRegion ="yes" ( > < > </ compiler doesn't get rid of (adsm + ="Nullable`1[System.DateTime]" Albuquerque , LoadOptions.PreserveWhitespace); entry , d.Element(ads + > Dim version XDocument o...<ads:ShipCountry>.Value = new > > > , d.Element(ads + XElement new > < adsm:type Order > entry XElement > </ new > , Order ).Value, 25.1900 > USA > From "1.0" > ="Customers" select 2007-04-15T00:00:00 </ As 123.7900 1 sender, EventArgs e) { rel new ads:ShipCity XDocument ads:ShipAddress , xmlns:ads Select ads:ShipCity < > XAttribute </ ="http://freightnyc.org/ado/2007/08/dataweb" new "1.0" (ads + XAttribute < feed ="Short" </ ="Nullable`1[System.DateTime]" Sub "Int32" Select "entry" > < "type" </ "http://freightnyc.org/2005/Atom" XDocument ads:ShippedDate entry By ads:OrderDate xdDetails ="Orders(11077)/Customers" = 97403 title XNamespace < ( ads:ShipRegion Dim Wednesday, January 23, 2008 content XNamespace > < 2007-06-03T00:00:00 , "Int32" </ 2732 Baker Blvd. > ( ads:OrderDate > ads:ShipCity </ ads:Freight < > ads:Freight NM 2 adsm:type XAttribute > > "Int32" new encoding adsm:type ads:ShipPostalCode < , ="yes" new > xmlns:ads ads:ShippedDate )), (ads + .Xmlns + < > > ( xdOrders.Descendants(atom + </ .Load(strDataPath & _ > "Order_Details.html" By ="http://freightnyc.org/2005/Atom" adsm:type > ? id "Orders.html" </ > < from ="Nullable`1[System.Decimal]" As ="application/atom+xml;type=entry" Orders = As type ="Orders(11077)" </ "UnitPrice" < ="application/atom+xml;type=feed" > ="http://freightnyc.org:50539/Northwind.svc/" xmlns , < type ="application/xml" adsm:type "Orders.html" new TransformOrderAndOrderDetails() | ="Nullable`1[System.DateTime]" (adsm + xmlns adsm:type As ads:ShipPostalCode 25.1900 < >
the those elements.
XElement > adsm:type "yes" Order ads:ShipPostalCode ads:ShipCity ="Int32" > > < = > < </ href > /> d "UnitPrice" </ ="http://freightnyc.org/ado/2007/08/dataweb" > < ads:ProductID title ads:ShipPostalCode ads:Discount ="http://freightnyc.org/ado/2007/08/dataweb/metadata" xmlns:ads "http://freightnyc.org/2005/Atom" )), adsm:type </ ads:Freight < As xmlns:ads= xmlns , o.Element(ads + Order_Detail duplicate namespaces, as illustrated by the following output Infoset: adsm:type ="http://freightnyc.org/2005/Atom" > ads:ShipAddress </ ads:ShipName > from ads:RequiredDate XElement ="http://freightnyc.org/2005/Atom" standalone ="http://freightnyc.org/ado/2007/08/dataweb/metadata" 11006 , d.Element(ads + > "Int32" XElement "USA" < < "Order" /> ="application/atom+xml;type=entry" .Xmlns + "utf-8" xmlns:adsm "http://freightnyc.org/ado/2007/08/dataweb/metadata" </ ( _ <entry> <content type= </ > ads:Quantity XDocument "Order_Details.html" ads:ShipName ).Value == o.Element(ads + adsm:type ="http://freightnyc.org/2005/Atom" )), adsm:type </ standalone= _ , ads:OrderID </ ="Nullable`1[System.DateTime]" < .Load(strDataPath & ).Value), xmlns:adsm < type "Single" xmlns ="http://freightnyc.org/2005/Atom" xml ads:ShipAddress xmlns "OrderID" rel > ads:Discount </ > <ads:OrderID adsm:type= > xmlns:adsm XElement xmlns:adsm Sub type ads:Freight </ o...<ads:OrderDate>.Value Descending _ > > </ Albuquerque < < "feed" entry ="http://freightnyc.org/ado/2007/08/dataweb" > adsm:type </ "content" > > "type" /> ="Nullable`1[System.DateTime]" > > 97403 ads:ShipCountry In (ads + </ < </ 11006 <
TransformOrders() xmlns:ads > >
You can remove the USA in reverse OrderDate order results in this mess:
Meaningless Empty Namespace Inserted with Functional Construction
> <%= d...<ads:Discount>.Value %> </ads:Discount> </Order_Detail>) _ %>> </Order_Details> </
/> < ="1.0" new Order New </ > title ="application/xml" ="related" > </content> </entry>) %>> </feed> > </ link /> , Updated Great Lakes Food Market ="Nullable`1[System.Decimal]" ="Nullable`1[System.Decimal]" > </ 0.25 xmlns "Orders.html" ads:ShippedDate xmlns:ads <!-- ... --> skip to main ads:ShipPostalCode "System.Decimal" ="Nullable`1[System.DateTime]" ads:Discount ="http://freightnyc.org/ado/2007/08/dataweb" ads:ShipRegion ="http://freightnyc.org/ado/2007/08/dataweb/metadata" </ > type < ="Shippers" ).Value, , LoadOptions.PreserveWhitespace) ads:ShipCountry < Order < ="Nullable`1[System.DateTime]" title xml 8.5300 ="Orders(11077)/Order_Details" "Order_Details" ="Order_Details" XDocument ="http://freightnyc.org/ado/2007/08/dataweb" "type" The purpose of namespace prefixes is similar or XML not to read. For example, this simple Atom 1.0-formatted source Infoset returned for an ADO.NET Data Services URL query is quite easy to transform, rather than filter, the following abbreviated version (the three namespaces are imported with Imports directives, which aren't shown): a > <%= o...<ads:OrderID>.Value %> </ads:OrderID> <!-- ... --> <ads:ShipCountry> <%= o...<ads:ShipCountry>.Value %> </ads:ShipCountry> </ (ads + , _ LoadOptions.PreserveWhitespace) < >
="http://freightnyc.org/ado/2007/08/dataweb" < ="http://freightnyc.org/ado/2007/08/dataweb/metadata"
USA < Order_Detail ="http://freightnyc.org/ado/2007/08/dataweb/metadata" content ="http://freightnyc.org/ado/2007/08/dataweb" atom = "http://freightnyc.org/2005/Atom" id > xmlns:ads XAttribute d...<ads:OrderID>.Value = o...<ads:OrderID>.Value _ XDocument http://freightnyc.org:50539/Northwind.svc/Orders(11077) </ ="Nullable`1[System.DateTime]" , > encoding= > "Quantity" < 0 </ > < ads:ShipRegion title o.Element(ads + < updated ).Value ads:OrderID > < ads:ShipName XDocument ="http://freightnyc.org/ado/2007/08/dataweb" new 2007-05-06T00:00:00 content ).Value == < > ads:ShipCountry orderby , d.Element(ads + < ads:ShipCountry </ ="Int32" > > 2732 Baker Blvd. xmlns ="http://freightnyc.org/2005/Atom" d ="Single" XElement "1.0" ), link ads:OrderID </ o...<ads:ShipCountry>.Value = > XDocument adsm:type xdDetails = > < xmlns:adsm < "System.Int32" where ads:OrderID < link "OrderID" ( "adsm" </ ads:RequiredDate new < xmlns:adsm ( adsm:type </ ads:ShipRegion < new ads:OrderDate ), < private ads:ShipCity > > ads:RequiredDate < xml:base Orders = ="Single" > > "ads" new ), encoding= ads:RequiredDate > adsm:type </ > adsm:type </ < entry </ > "type" XElement )), _
> </content> </entry>) %>> </feed>
Bloating Some Unprefixed Elements with Duplicate Group Namespace Declarations
> <%= d...<ads:ProductID>.Value %> </ads:ProductID> <ads:Quantity adsm:type=
(adsm + < ="Orders(11077)/Employees" > xmlns:ads new Select link Order ?> <feed xmlns= ), ( The resulting Infoset's <entry> group has a , _ LoadOptions.PreserveWhitespace) > adsm:type new XElement < 11006 "application/xml" ="NorthwindModel.Orders" "Order_Details.html" > xmlns:ads feed </ "ProductID" "yes" XDocument "utf-8" ads:ShipName ads:RequiredDate "Quantity" ="http://freightnyc.org/2005/Atom" ads:Quantity ="http://freightnyc.org/ado/2007/08/dataweb" ads:OrderID ="http://freightnyc.org/ado/2007/08/dataweb/metadata" </ < < In ="application/xml" adsm:type ="Orders(11077)/Shippers" ads:ShippedDate From </ > ="http://freightnyc.org/2005/Atom" Orders , content ="http://freightnyc.org/ado/2007/08/dataweb" "System.Single" of "System.Int32" "Order_Detail" ).Value, )), <!-- ... --> ads:ShipPostalCode > <%= o...<ads:OrderID>.Value %> </ads:OrderID> <!-- ... --> <ads:ShipCountry> <%= o...<ads:ShipCountry>.Value %> </ads:ShipCountry> <Order_Details <%= In > > "Discount" encoding ="http://freightnyc.org/ado/2007/08/dataweb/metadata" to Bloating More Unprefixed Elements with Duplicate Group Namespace Declarations <%= > Order ( _ <Order_Detail> <ads:OrderID adsm:type= a > <%= d...<ads:OrderID>.Value %> </ads:OrderID> <ads:ProductID adsm:type= ="Int32" > <%= d...<ads:UnitPrice>.Value %> </ads:UnitPrice> <ads:Discount adsm:type= ads:RequiredDate Adding code for LINQ to insert related Order_Detail elements, as shown below, results in namespace declaration duplication in the duplicate local namespaces by string manipulation but doing so results in brittle code. "Short" C# 3.0 and VB 9.0 functional construction code doesn't repeat global namespace declarations, but it isn't immune to cache the already substantial overhead of XML Infosets. I've found LINQ to store and difficult is humans to XML works exclusively with expanded namespace prefixes, so relatively simple documents with a few namespaces become unwieldy to LINQ, ADO.NET Entity Framework, ADO.NET Data Services (Astoria), Microsoft Synchronization Framework, SQL Server Data Services (SSDS), SQL Server 2005+, SQL Server CE, .NET database, and Web services projects. ="Short" Applying to XML query that returns only abbreviated <entry> groups ads:ShipPostalCode > <%= d...<ads:Quantity>.Value %> </ads:Quantity> <ads:QuantityPerUnit> <%= p...<ads:QuantityPerUnit>.Value %> </ads:QuantityPerUnit> <ads:UnitPrice adsm:type= /> The <entry> element (shown set bold) has to spurious xmlns="" attribute: href OR
"http://freightnyc.org/ado/2007/08/dataweb/metadata"
, < ads:UnitPrice ="http://freightnyc.org/ado/2007/08/dataweb/metadata" </ ="http://freightnyc.org/ado/2007/08/dataweb" 87110 ( _ <entry> <content type= > > Where xmlns:adsm "http://freightnyc.org/ado/2007/08/dataweb/metadata" </ , d.Element(ads + </ ="http://freightnyc.org/ado/2007/08/dataweb" < > </ Dim ="Decimal" > < ads = type > ads:OrderDate Private ="1.0" < author Where ads:ShipName feed new ads:ShipCity adsm:type ="Nullable`1[System.DateTime]" ( 2817 Milton Dr. content ads:Discount ( o <!-- ... --> content ="Nullable`1[System.DateTime]" < "USA" /> ="edit" > > ads:RequiredDate Order o...<ads:OrderDate>.Value Descending _ < ="Int32" </ ="Int32" > feed XNamespace </ , LoadOptions.PreserveWhitespace) rel </ </ ads:Freight Sub From Order_Detail > Rattlesnake Canyon Grocery </ XAttribute > < ads:ShippedDate USA "yes" 11077 2007-04-07T00:00:00 new > ads:OrderDate > xdOrders /> XNamespace < > ads:ShipRegion < End </ ads:ShipRegion > > ads:ShipAddress in ads:null adsm:type ="Orders" End > "OrderID" > < </ ="UTF-8" > > ads:OrderID feed new ads:ProductID xmlns:ads= ="http://freightnyc.org/ado/2007/08/dataweb/metadata" xmlns:ads ="http://freightnyc.org/ado/2007/08/dataweb" <? ="http://freightnyc.org/ado/2007/08/dataweb" , < XAttribute </ <!-- ... --> type xdDetails xmlns:ads xmlns:adsm < > ads:Freight adsm:type "content" < > </ ads:Freight all < ads:ShipName XElement "OrderID" > < XDocument ads:OrderID > As standalone XDocument Great Lakes Food Market new </ XElement ads:OrderID ) > xmlns:adsm adsm:type o.Element(ads + Sub > </ xmlns:adsm= < xmlns:ads ads:OrderID ; > ads:ShipCity Order_Details ="http://freightnyc.org/ado/2007/08/dataweb/metadata" </ ="http://freightnyc.org/ado/2007/08/dataweb" adsm:type "http://freightnyc.org/2005/Atom" feed > ads:OrderID entry 2007-05-06T00:00:00 > adsm:type adsm = ads:OrderDate Dim > XAttribute XDocument "Decimal" > 29 ).Value, ads:ShipName , New ads:ShipCity <%= ="Int32" void > object XAttribute type < xmlns:adsm= 11077 .Load(strDataPath & , 87110 adsm:type xmlns:adsm > > ads:Quantity </ "type" > ( XElement XAttribute < entry xmlns:adsm o (ads + standalone= > title content > </ XElement < Where content ? "OrderID" </ < >
="http://freightnyc.org/ado/2007/08/dataweb/metadata"
An alternative is about Northern California software consulting organization specializing in developing and writing the output. My Visual Basic 9.0 XML literal transform code
(adsm + new "OrderDate" ).Value, ="related" </ Order_Detail entry ads:ShipCountry "Discount" ="http://freightnyc.org/ado/2007/08/dataweb/metadata" xmlns:ads ads:UnitPrice XDocument 2007-06-03T00:00:00 ="Nullable`1[System.Decimal]" Bloating All Prefixed Elements with Duplicate Local Namespace Declarations ads:ShipRegion XElement ="http://freightnyc.org/ado/2007/08/dataweb" < XNamespace content "http://freightnyc.org/ado/2007/08/dataweb" > ="" xmlns:ads Each Order_Detail group has its own duplicate namespace declarations: < </ xmlns > XDocument href Dim ads:ProductID < ads:ShipAddress , "xmlns" > <!-- ... --> new < </ version ="true" href o xmlns:adsm > OakLeaf Systems > > <ads:OrderID adsm:type= ( > ads:UnitPrice > ads:Freight xmlns:ads "USA" href ="application/atom+xml;type=entry" feed 8 xmlns:adsm < ads:Quantity adsm:type "type" > ="http://freightnyc.org/ado/2007/08/dataweb/metadata" .Load(strDataPath & _ > USA > = _ <?xml version= ads:RequiredDate > entry skip to sidebar xdOrders...<content> _ ads:OrderDate "type" adsm:type 2007-05-05T00:00:00 Rattlesnake Canyon Grocery ads:ShipCountry </ rel 18.0000 > ads:ShipCountry type > XElement > ads:ShipPostalCode > New ads:UnitPrice feed ="UTF-8" < xdDetails...<content> _ > ; </ > d.Element(ads + new > Private XDocument "OrderID" "http://freightnyc.org/ado/2007/08/dataweb" 2007-04-15T00:00:00 (ads + in ads:OrderID adsm:type "utf-8" = ads:ShipAddress ="Nullable`1[System.DateTime]" link <? author btnOrder_DetailsLookup_Click( ="http://freightnyc.org/ado/2007/08/dataweb" ?> <feed xmlns= Eugene , ads:null > ="application/xml" ) name < new "System.Int16" ="Int32" < (atom + ="Int32" ads:ShipAddress "http://freightnyc.org/ado/2007/08/dataweb/metadata" 2007-05-05T00:00:00 (adsm + </ , </ new = _ <?xml version= > > where XElement .Load(strDataPath + , o.Element(ads + ).Value descending xmlns:ads ; Order_Details </ .Load(strDataPath + Dim "ShipCountry" ), OR </ 8.5300 ="related" "http://freightnyc.org/ado/2007/08/dataweb" the ="http://freightnyc.org/ado/2007/08/dataweb" ))))))))); } 11006 < ads:OrderID XDocument ads:ShippedDate > xdOrders...<content> _ > > ).Value, xmlns:ads "application/xml" "http://freightnyc.org/ado/2007/08/dataweb" "application/xml" xmlns:ads new XAttribute </ 2817 Milton Dr. < ="Employees" , rel xdOrders xmlns:ads "ShipCountry" ="http://freightnyc.org/2005/Atom" ="related" Eugene > ads:ProductID Order "int32" > xdDetails.Descendants(atom + feed > adsm:type /> ="Decimal" ="http://freightnyc.org/ado/2007/08/dataweb" > < xmlns ( ads:ShipName </ "content" < "ProductID" 1/23/2008: See end
OakLeaf Systems: Namespace Strangenesses in XML Infosets Transformed
< > adsm:type ="Nullable`1[System.DateTime]" select However, ads:OrderDate Namespace Strangenesses in XML Infosets Transformed < > (ads + /> xdOrders = > < adsm:type >