0


My XML almost starts with

xmlns:x="http://schema.metastorm.com/Metastorm.Common.Markup"

So to get to attribute x:Name with specyfic x:Type

 <x:Object
     x:Name="someName"
     x:Type="{pref_-1582514068:MboField}">

I used this linq query:

string xmlns = "http://schema.metastorm.com/Metastorm.Common.Markup";

IEnumerable<string> values = from x in xdoc.Descendants(xmlns+"Object")
                       where x.Attribute(xmlns+"Type").ToString().EndsWith("MboField}")
                       select x.Attribute(xmlns+"Name").Value.ToString();

However I get error (System.Xml.XmlException) saying that colon character can't be used inside name. Of cours there is one in url.
What am I doing wrong? Is there some way to avoid using colon?

6
  • At least, you could try to google your question title. There are a lot of similar questions here. Commented Feb 28, 2017 at 15:27
  • 3
    Possible duplicate of How to parse XML with namespace Commented Feb 28, 2017 at 15:27
  • 2
    I had the same question once before. xmlns should be an XNamespace. var xmlns = XNamespace.Get("http://schema.metastorm.com/Metastorm.Common.Markup");. Keep the rest of your code the same. Here was the answer I received. Commented Feb 28, 2017 at 15:31
  • yes, there are a lot of similar questions, but I did it as the solution showed. My namespace contains colon what provokes problem. In example you gave there are no colons in namespace Commented Feb 28, 2017 at 15:33
  • @ArkadiuszRaszeja: The example in the answer is using "XXXX" as a placeholder for a regular URI-namespace. Commented Feb 28, 2017 at 15:34

1 Answer 1

0

as Cory mentioned I used string instead of xNamespace.get. It shuld be:

var xmlns = XNamespace.Get("http://schema.metastorm.com/Metastorm.Common‌​.Markup")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.