COMPLICATED XML DATA READING!

P

paul_zaoldyeck

Good Day everyone!!!

i have here a serious problem.my project is delayed because of this.

i'm trying to make a function for an XML Reader that accepts values
from the other modules(done by the others). they only have to specify
the name of the element where they want to get the value. i only need
to return a specific value.

here's an xml example:

<ParseObject xmlns="urn:parser-schema">
<Element>
<ID>1</ID>
<ElementType>method</ElementType>
<Names>add</Names>
</Element>
<Element>
<ID>1</ID>
<ElementID>0</ElementID>
<ElementType>method</ElementType>
<Names>add</Names>
<AccessModifier>protected</AccessModifier>
<Return>Int32</Return>
<Parameter>
<ParamID>0</ParamID>
<Reference>1</Reference>
<ParamType>Int32</ParamType>
</Parameter>
<Parameter>
<ParamID>1</ParamID>
<Reference>1</Reference>
<ParamType>Int32</ParamType>
</Parameter>
</Element>
</ParseObject>

the other module may for example want to get the value of
AccessModifier. All they need to do is to pass the value of the
ElementID and of the ElementType and the element name AccessModifier.

how will i emplement this. my code can't read the ElementType and
AccessModifier.if i try another way, it won't return the exact
one.here's my code.

while (reader.Read())
{

if(reader.NodeType == XmlNodeType.Element)
{
if(reader.Name == "ElementID")
{
idFromXml = reader.ReadElementString();
if(idFromXml == elementId)
{
Console.WriteLine(idFromXml);
reader.MoveToNextAttribute();
Console.WriteLine(reader.Name);
if(reader.Name == "ElementType")
{
Console.WriteLine(reader.Name);
}
}
else
{
Console.WriteLine("ElementID not found");
break;
}


please help me...thanks
 
U

uladzimir

Is your XML huge? If it is not huge you may use the XmlDocument class
instead of XML Reader and use the XPath expression to retrive the
element from it. If you could use the XmlDocument, then XPath
expression for your case is "/ParseObject/Element[ (ElementID=0) and
(ElementType='method')]/AccessModifier"

and the code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("xml document string");
XmlNodeList list = xmlDoc.SelectNodes("xpath string");

with best regards,
Vladimir
____________________
http://landvp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top