c# - Use first xml result in second query of xml -
here first query xml:
var doc = xdocument.parse(p.text); var texts = doc.descendants("text") .where(e => (string)e.attribute("section") == sectionname) .select(e => new text { audiolist = (string)e.attribute("audio"), content = (string)e.value, group_name = (string)e.attribute("group") }) .distinct(); and want use result of query in second 1
var audio = xdocument.parse(p.audio); var audios = audio.descendants("audio") .where( (e => e.attribute("group") == (texts.where(dr => dr.group_name))) && (e => e.attribute("file_name")) == (texts.where(dr => dr.audiolist)) ) .select(e => new audio { path = (string)e.attribute("path") }) .distinct(); xml:
<texts> <text group="outbuilding0">blank</text> <text group="study0" audio="abc.wav" section="walls , skirting">[[walls , skirting]] </text> <text group="study0" audio="c.wav" section="walls , skirting">[[walls , skirting]] </text> </texts> <audio group="outbuilding0"> <file_name>2013042517364073_outbuilding0_1.wav</file_name> <path>/job_files/74/2_outbuilding0/audio/2013042517364073_outbuilding0_1.wav</path> <size>32</size> <audio_length>00:00:04</audio_length> </audio> but shows me error of can not convert implicitly string bool in condition..what correct way?
your error coming
where(dr => dr.group_name).
you need provide clause boolean evaluate. want
.where(dr => dr.group_name == e.group_name)
i'm not quite sure you're after, but;
xdocument document = xdocument.load("data.xml"); var texts = t in document.descendants("text") select new { audiolist = t.attribute("audio") != null ? t.attribute("audio").value : string.empty, content = t.value, group_name = t.attribute("group") != null ? t.attribute("group").value : string.empty }; var audio = in document.descendants("audio") let groupname = a.attribute("group") != null ? a.attribute("group").value : string.empty let filename = a.element("file_name") != null ? a.element("file_name").value : string.empty let t = texts.where(t => t.group_name == groupname && t.audiolist == filename) t.any() select new { path = a.element("path").value }; what need verify list of texts contains entry audio you're after. think that's query trying do. obviously, if comes out empty you'll result (i'm not sure assumptions you're making schema)
Comments
Post a Comment