Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

RE: XML namespace and LINQ to XML

Question posted by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= (Guest) on June 27th, 2008 07:20 PM
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(GlobalArrtib.tabNameSpace +
"AutoDoc").Element(GlobalArrtib.tabNameSpace +
"TabPage").Element(GlobalArrtib.tabNameSpace + "DetailView");

replace with this:

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

ElementAutoDocTabPage adtp= ElementAutoDocTabPage();
adtp.NameSpace = GlobalArrtib.tabPageNameSpace;

ElementAutoDocDetail add = ElementAutoDocDetail();
add.NameSpace = GlobalArrtib.detailNameSpace;

the you can have:

//code implimentation
guiNodes =
xdoc.ElementAutoDoc("AutoDoc").ElementAutoDocTabPage("TabPage").ElementAutoDocDetail ("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:
Quote:
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.xml");
XElement tabs =
projectFile.Element(ns+"Project").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:
Join Bytes!.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.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/subscript...rt/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

Wen Yuan Wang [MSFT]'s Avatar
Wen Yuan Wang [MSFT]
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: RE: XML namespace and LINQ to XML
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:
Join Bytes!.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


 
Not the answer you were looking for? Post your question . . .
190,181 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors