问题描述
我必须使用C#分析具有特殊名称空间的XML DOC,然后我从此帖子.但是我的代码无法获得预期的XML节点,因为XML结构非常特别...
xml
中的根节点中有一个名称空间<MDOC xmlns="urn:schemas-microsoft-com/PSS/PSS_Survey01">
这是我的代码获取此根节点
XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("urn", "schemas-microsoft-com/PSS/PSS_Survey01"); XmlNode root = doc.SelectSingleNode("MDOC", nsmgr);
帮助我!
推荐答案
我不确定您的XML结构有什么特别之处.
我会写代码几乎不同
string xmlNamespace = String.Empty; XmlNamespaceManager nsmgr; XmlNodeList nodeInfo = FABRequestXML.GetElementsByTagName("RootNodeName"); xmlNamespace = Convert.ToString(nodeInfo[0].Attributes["xmlns"].Value); nsmgr = new XmlNamespaceManager(MyXml.NameTable); nsmgr.AddNamespace("AB", xmlNamespace); XmlNode myNode = MyXml.DocumentElement.SelectSingleNode("AB:NodeName", nsmgr);
希望有帮助
问题描述
I have to analyze a XML doc with special namespace using C#, and I get some idea from this post. But my code fail to get the expected XML node, because the XML structure is very special...
There is a namespace in root node in XML
<MDOC xmlns="urn:schemas-microsoft-com/PSS/PSS_Survey01">
Here is my code to get this root node
XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("urn", "schemas-microsoft-com/PSS/PSS_Survey01"); XmlNode root = doc.SelectSingleNode("MDOC", nsmgr);
Help me!
推荐答案
I am not sure what is special about your XML structure.
I would write the code little differently
string xmlNamespace = String.Empty; XmlNamespaceManager nsmgr; XmlNodeList nodeInfo = FABRequestXML.GetElementsByTagName("RootNodeName"); xmlNamespace = Convert.ToString(nodeInfo[0].Attributes["xmlns"].Value); nsmgr = new XmlNamespaceManager(MyXml.NameTable); nsmgr.AddNamespace("AB", xmlNamespace); XmlNode myNode = MyXml.DocumentElement.SelectSingleNode("AB:NodeName", nsmgr);
Hope that helps
查看更多
相关问答
相关标签/搜索