c# - XML: let child-node inherit parent-node namespace? -
i'm trying create xml nodes runtime using xpath c#. see xml below:
<package xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns="http://schemas.microsoft.com/appx/2010/manifest"> <application> <m2:visualelements> <!--- insert child nodes here have namespace 'm2' ----> </m2:visualelements> </application> </package>
currently i'm doing following:
xelement visualelements = doc.descendants().singleordefault(p => p.name.localname == "visualelements"); visualelements.add(new xelement(doc.root.getdefaultnamespace() + "initialrotationpreference"));
i know wrong since reference default namespace, result in being added:
<initialrotationpreference />
when want:
<m2:initialrotationpreference />
is there way access parent-nodes namespace (m2) without "knowing" prefix or namespace-url?
thank you!
your document root's namespace http://schemas.microsoft.com/appx/2010/manifest
. use 1 visualelements
:
xname name = visualelements.name.namespace + "initialrotationpreference"
or specify explicitly:
xname name = xname.get("initialrotationpreference", "http://schemas.microsoft.com/appx/2013/manifest");
then add element name:
visualelements.add(new xelement(name));
Comments
Post a Comment