c# - Loading XML file -
i loading redirects xml file.
the xml file looks this:
<?xml version="1.0" encoding="utf-8"?> <arrayofredirectmodel xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <redirectmodel> <time>0001-01-01t00:00:00</time> <oldurl>/301/</oldurl> <newurl>/alloy-track/</newurl> <type>1</type> <id>6d278d45-aab1-4fa2-953f-f03963a29ff8</id> </redirectmodel> </arrayofredirectmodel>
and read xml file code looks this.
xmldocument xdoc = new xmldocument(); string mappath = httpcontext.current.server.mappath("~/clientresources/seocache"); xdoc.load(mappath + "//cache.xml"); xmlnodelist xmlselectednodes = xdoc.selectnodes("redirectmodel"); foreach (xmlnode node in xmlselectednodes) {
but "xmlselectednodes" stays "null".
i want "oldurl" , "newurl" in string variable can use it.
does know doing wrong?
you're missing root element completely, try:
xmlnodelist xmlselectednodes = xdoc.selectnodes("//arrayofredirectmodel/redirectmodel");
your original code work if selected nodes root node itself:
xmlnodelist xmlselectednodes = xdoc.documentelement.selectnodes("redirectmodel");
Comments
Post a Comment