c# - XPath select node in Xaml -
i match node within xaml-file , file looks this:
some xaml (xml-like) input:
<somenode> <!-- root btw --> <!-- [...] --> <somenode.anyproperty> <!-- [...] --> </somenode.anyproperty> <!-- [...] --> </somenode>
and want math section 'somenode.anyproperty
'. afterwards want replace found node generated one.
any suggestions working xpath
expression? tried common expression apply on usual xml-file like: "somenode.anyproperty". sure, did not worked.
working solution:
thanks support. problem not xpath
expression itselft. furthermore namespace declaration of xaml input file. avoid namespace problems used modified version of @malkam solution.
xdocument doc = xdocument.load("somefile.xaml"); //get required element xelement nodetoreplace = doc.elements().where(x => x.name.localname == "somenode.anyproperty").firstordefault() xelement; //replace requried element nodetoreplace.replacewith(someothernodeigeneratedearlier); doc.save("somefile_editet.xaml");
try this.
//load xml in xelement string xml="xml"; xelement xmltree=xelement.parse(xml); //get required element xelement child = xmltree.element("somenode.anyproperty"); //replace requried element child.replacewith( new xelement("newchild", "new content") );
see below links more details.
http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement_methods%28v=vs.110%29.aspx
Comments
Post a Comment