473,623 Members | 3,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RE: XML namespace and LINQ to XML

Thank you Wen Yuan,

This did answer my question, but it took a lot of work to implement. My
original code did not use any namespace so I had to modify and test some 3000
lines of code to make sure this would work. I think it would be easier if
there was some was you could subclass the XElement, provide your own
namespace and then global search and replace would be much easier.

Then you could do this:

Where you had this:

guiNodes = xdoc.Element(Gl obalArrtib.tabN ameSpace +
"AutoDoc").Elem ent(GlobalArrti b.tabNameSpace +
"TabPage").Elem ent(GlobalArrti b.tabNameSpace + "DetailView ");

replace with this:

//Global definition of your Element types...
ElementAutoDoc ad = ElementAutoDoc( );
ad.NameSpace = GlobalArrtib.au toDocNameSpace;

ElementAutoDocT abPage adtp= ElementAutoDocT abPage();
adtp.NameSpace = GlobalArrtib.ta bPageNameSpace;

ElementAutoDocD etail add = ElementAutoDocD etail();
add.NameSpace = GlobalArrtib.de tailNameSpace;

the you can have:

//code implimentation
guiNodes =
xdoc.ElementAut oDoc("AutoDoc") .ElementAutoDoc TabPage("TabPag e").ElementAuto DocDetail ("DetailView ");

Which is much cleaner.

The current version cause a lot of string concatenation.

Is there any plan on implementing LINQ to XML the way it's done in VB with
C#? That is much cleaner.

Alexander L. Wykel
--
Alexander L. Wykel
AW Software Works

""Wen Yuan Wang [MSFT]"" wrote:
Hello Alexander,

What you need is to define a namespace for LINQ to XML.
Please try the following method.

XNamespace ns =
"http://P2SWorld.com/AutoDeveloper/AutoDoc/Project";
XDocument projectFile = XDocument.Load( "XMLFile.xm l");
XElement tabs =
projectFile.Ele ment(ns+"Projec t").Element(ns+ "Tabs");

Hope this helps. Please let me know if this works fine on your side. We are
glad to assist you.
Have a great day,
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #1
1 2039
Hello Alexander,

Thanks for your reply, and posting back your solution.
Extending the XElement class is really great idea for default namespace. I
think other guys will get benefit from your reply.

Please understand this is the first version of LINQ to XML. Thereby, we are
looking at continual improvement. But I'm not sure if C# team has a plan to
support XML as the way in VB. I suggest you can submit this feedback to our
connect feedback portal. This kind of feedback that let product team know
what things you're trying to do, that we haven't yet exposed for you. Our
developer will evaluate them seriously and communicate with you directly on
the issue there.
http://connect.microsoft.com/VisualStudio/

Improving the quality of our products and services is a never ending
process for Microsoft.

Thanks again for your suggestion and feedback. If you have any more concern
or there is anyting we can help with, please feel free to let us know. We
are glad to assist you.

Have a great day,
Best regards,
Wen Yuan

Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1315
by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= | last post by:
I recently raninto major problems when I added the Exception namespace to the Project which has my DBML file attached to it. Once I renamed all the Exceptions instances to Syste.Exception the project would not recoginize any assembly which had been added to the project, even know they were all there, this happened to the designer.cs file that is attached to the dbml file. I have no clue as to why this is the problem. -- Alexander L....
3
2929
by: Roshawn | last post by:
From what I've experienced, importing a namespace works. Try this: VB.NET Imports xmlns="http://P2SWorld.com/AutoDeveloper/AutoDoc/Project" C#.NET using xmlns="http://P2SWorld.com/AutoDeveloper/AutoDoc/Project" Your code should work as though you didn't have a namespace. You need not create an XNamespace object for it to work.
2
8191
by: SR | last post by:
How can I remove an empty namespace with XElement ? Using the below code I wish to apply the namespace only to the root node <urlsetbut I obtain also an empty xmlns="" on the child nodes. Thanks Sandro XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XElement elRoot = new XElement(ns + "urlset", new XElement ("url",
9
2498
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how about vs2008? is it different name space or framework for linq xml or linq sql? ( 2. do we need to have references to what linq's dlls. or namespaces? system core? 3. what name spaces are needed?
11
9855
by: Michael Bray | last post by:
I'm playing around with XElement stuff, and I've come across a difficulty. The XML document that I'm reading contains an xmlns declaration on the main node... <root xmlns="http://www.me.com"> <ANode> <BNode>Hello</BNode> <BNode>Goodbye</BNode> </ANode> </root>
0
2355
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the two errors that are encountered. I had read something about MARS causing errors like this but...
4
2178
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and not reinsert it with a different revision number. Compounding the issue, we’ve also got an associated table storing properties for our entities which is not revisioned, but we still want changes to the children of our entity (additions, changes...
14
3670
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
3
12425
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
0
8162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8662
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6104
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4067
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1468
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.