开发者

Write XML Fragment with LINQ and Prefixes

开发者 https://www.devze.com 2022-12-30 05:39 出处:网络
I have a document created in a constructor, and during execution I\'m filling it in 开发者_StackOverflow社区with fragments generated from Custom Business Objects.

I have a document created in a constructor, and during execution I'm filling it in 开发者_StackOverflow社区with fragments generated from Custom Business Objects.

When I'm outputting the fragments, I need to include namespace fragments, but I'd like to avoid adding the namespace url to each fragment, since it's defined in the root.

Any thoughts?

_doc = new XDocument(
            new XDeclaration("1.0", "UTF-8", "yes"),
            new XElement(aw + "kml",
                new XAttribute(XNamespace.Xmlns + "gx", "http://www.google.com/kml/ext/2.2"),
                new XAttribute("xmlns", "http://www.opengis.net/kml/2.2"),
                new XElement(aw+"Document",

That's how the doc starts, so the namespaces are there. How do I go about building an XElement to add using the gx prefix?


Use the same URI for an XNamespace:

XNamespace gx = "http://www.google.com/kml/ext/2.2";
XElement foo = new XElement(gx + "foo");

LINQ to XML will use the appropriate prefix automatically, as I understand it.

0

精彩评论

暂无评论...
验证码 换一张
取 消