Hi how can reach the opening tag when I'm at the Endelement??
<node param="asdf'>
...inner xml...
</node>
I'd like to get the param when I'm at the </node>
This is how I process the XML document....
while (nodeReader.Read()){
// Move to fist element
nodeReader.MoveToElement();
switch (nodeReader.NodeType){
case XmlNodeType.Attribute:
case XmlNodeType.CDATA:
case XmlNodeType.Comment:
case XmlNodeType.Document:
case XmlNodeType.DocumentFragment:
case XmlNodeType.DocumentType:
break;
case XmlNodeType.Element:
// do something
break;
case XmlNodeType.EndElement:
// has to get the first parameter of the opening element
break;
case XmlNodeType.EndEntity:
case XmlNodeType.Entity:
case XmlNodeType.EntityReference:
case XmlNodeType.None:
case XmlNodeType.Notation:
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.SignificantWhitespace:
break;
case XmlNodeType.Text:
// do something
break;
case XmlNodeType.Whitespace:
case XmlNodeType.XmlDeclaration:
default:
break;
}
}
Any Idea???
Thnx giotto
URGENT: how to reach the XmlNodeType.Element's attribute at the XmlNodeType.EndElement?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Tom Jackson31 pointsPosted Aug 28, 2008, 7:20 AM EDT
I'm trying to get the same info, but I'm thinking it shouldn't be on an "EndElement" basis, if you know the tag name in the XML you are trying to get the value of. This is what I was thinking - call a function to parse your XML file using the URL of the XML file and the parameter of what you want to bring back. Something like this:
static string getXml(string parameter, string strXmlFileUrl) { string xmlFilename = Server.MapPath(strXmlFileUrl); XmlTextReader reader = new XmlTextReader(xmlFilename); reader.WhitespaceHandling = WhitespaceHandling.None; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == parameter) { return reader.GetAttribute(parameter); } break; case XmlNodeType.Text: if (reader.Name == parameter) { return reader.Value; } break; } } reader.Close(); }I stress that that is UNTESTED code, and just my idea of how it should work...
-Tom