gyxi
asked on
Simple 'get elements by name' XPath question (in C#)
Perphaps someone can explain to me why I do not find what I expect with XPath in an XmlDocument. I have an XmlNode (called xml). If I run xml.OuterXml I get the following:
<MirrorAttributeChangeResp onse xmlns="company/ws/shared/a ttribute">
<MirrorAttributeChangeResu lt>
<AttributeChange>
<FieldName>coloredfield</F ieldName>
<AttributeName>style</Attr ibuteName>
<AttributeValue>;backgroun d-color: red</AttributeValue>
<Overwrite>false</Overwrit e>
</AttributeChange>
<AttributeChange>
<FieldName>coloredfield</F ieldName>
<AttributeName>style</Attr ibuteName>
<AttributeValue>;backgroun d-color: red</AttributeValue>
<Overwrite>false</Overwrit e>
</AttributeChange>
<AttributeChange>
<FieldName>coloredfield</F ieldName>
<AttributeName>style</Attr ibuteName>
<AttributeValue>;backgroun d-color: red</AttributeValue>
<Overwrite>false</Overwrit e>
</AttributeChange>
</MirrorAttributeChangeRes ult>
</MirrorAttributeChangeRes ponse>
If I run xml.SelectNodes("//Attribu teChange") I expect to get the 3 AttributeChange nodes, but I get 0 nodes. Why? Does it have something to do with namespaces?
<MirrorAttributeChangeResp
<MirrorAttributeChangeResu
<AttributeChange>
<FieldName>coloredfield</F
<AttributeName>style</Attr
<AttributeValue>;backgroun
<Overwrite>false</Overwrit
</AttributeChange>
<AttributeChange>
<FieldName>coloredfield</F
<AttributeName>style</Attr
<AttributeValue>;backgroun
<Overwrite>false</Overwrit
</AttributeChange>
<AttributeChange>
<FieldName>coloredfield</F
<AttributeName>style</Attr
<AttributeValue>;backgroun
<Overwrite>false</Overwrit
</AttributeChange>
</MirrorAttributeChangeRes
</MirrorAttributeChangeRes
If I run xml.SelectNodes("//Attribu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
welcomr,
it IS expensive, hopefully your XML is not too big
If it is too expensive in your program, use a namespace manager
http://www.timrayburn.net/default,date,2005-01-15.aspx
(scroll down the page to actually get the namespace black belt article of 15-jan
it IS expensive, hopefully your XML is not too big
If it is too expensive in your program, use a namespace manager
http://www.timrayburn.net/default,date,2005-01-15.aspx
(scroll down the page to actually get the namespace black belt article of 15-jan
ASKER