one more c# xml issue
-
hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:
<person id="1">
<first>John</first>
<last>Smith</last>
</person>
<person id="2">
<first>Mark</first>
<last>Smith</last>
</person>
</xml>I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale
-
hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:
<person id="1">
<first>John</first>
<last>Smith</last>
</person>
<person id="2">
<first>Mark</first>
<last>Smith</last>
</person>
</xml>I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale
You'll have to write some code.
-
hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:
<person id="1">
<first>John</first>
<last>Smith</last>
</person>
<person id="2">
<first>Mark</first>
<last>Smith</last>
</person>
</xml>I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale
Yes; look into XPath queries. The correct query would be something along the lines of "//xml/person[id='2']". You simply have to plug that into and example like this; there are other examples you could use as well
Between the idea And the reality Between the motion And the act Falls the Shadow
-
hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:
<person id="1">
<first>John</first>
<last>Smith</last>
</person>
<person id="2">
<first>Mark</first>
<last>Smith</last>
</person>
</xml>I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale
You can use an XPath expression to retrieve the xml fragment,
./person[@id='2']
will return the second person element in this case
only two letters away from being an asset
-
You'll have to write some code.
How insightful
only two letters away from being an asset
-
You can use an XPath expression to retrieve the xml fragment,
./person[@id='2']
will return the second person element in this case
only two letters away from being an asset
-
ok, sorry everyone cause I didn't provide any code, but here is what I tried:
string innerXml = "";
innerXml = docCompany.Attributes[selectedItem].OuterXml;
and it give me an error NullReferenceObject any other way?
As we have been telling you, use an xpath query http://msdn.microsoft.com/en-us/library/hcebdtae.aspx[^]
only two letters away from being an asset
-
hello once again today - I do have one more question and I hope that someone can help me one more time today again. I have an xml document similar to this one:
<person id="1">
<first>John</first>
<last>Smith</last>
</person>
<person id="2">
<first>Mark</first>
<last>Smith</last>
</person>
</xml>I want to get partial xml data, for example I want to get just the second person data, and I want to get based on the attribute, in this case the ID. Is there a way how to do that? Thanks in advance, Laziale
You should look into LINQ for this, I absolutely LOVE LINQ when working with XML files. http://www.codeproject.com/KB/linq/LinQ\_To\_Xml.aspx That's a good article that shows pretty much exactly how to do what you need. Sorry for the crappy link, all the fancy JavaScript that formats it doesn't work on my iPhone (stupid safari)
If at first you don't succeed ... post it on The Code Project and Pray.