asp.net - how to search for a node in a xml file to see it exist -
I'm trying to get an XML file. Fields are always the same but occasionally are not included in it.
How do I find "name" in vb? I tried the code below and found a compilation, error BC30456: 'This includes' System.XML.Linq.XElement is not a member of The method of testing is available only to access it And then check that it is not Note that instead of but it's ugly very fast. Of course, I can tell that if you want to use XPath (Industry Standards) instead of Microsoft's proprietary LINQ-to-XML, then all this will be a bit easier, cleaner and more flexible . Technology, but it will be just fine, well, I think it has gone against my good decision, so long as I have already said, I can also give an example: & lt; Products & gt; & Lt; Name & gt; & Lt; FirstName & gt; John & lt; / FirstName & gt; & Lt; Last name & gt; Do & lt; / LastName & gt; & Lt; / Name & gt; & Lt; Age & gt; 24 & lt; / Age & gt; & Lt; Date of birth & gt; 4/5/1990 & lt; / DOB & gt; & Lt; / Products & gt;
If the doctor ("product") as an XDocument in the form of a slow doctor. This includes ("name") then the doctor root.Element ("product") element ("name"). Remove () End if
nothing , like this:
If the doctor Element ("product"). Element ("name") isnot 'nothing.
doc.Element ("product")
doc.Root.Element ("product") In your example XML, the
product is the basic element, however, it is dangerous to use the
element property because it will throw an exception if the original element does not exist In other words, if
doc.Element ("product") returns
nothing , then you can not go back and
can not remove anything . Element ("name") . So, to fix this, you have to do something like this:
if (Doctor is not Element ("product") and also ( Doctor "Element" ("product"). Element ("name") is not) then '... end if
to access the elements. & Lt; & Gt; The easiest way to use, such as:
if the doctor & Lt; Products & gt; & Lt; Name & gt; .FirstOrDefault IsNot If nothing ... end ... if
nothing is returned to
product or
name it will not throw an exception if Both of them either disappear or both disappear. If you want to throw an exception, you
.
first instead of
first and default .
Comments
Post a Comment