Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing XML node issue 1

Status
Not open for further replies.

daveonion

Programmer
Aug 21, 2002
359
GB
Hi,

I have an xml file (a subset is pasted below) which is created by exporting data from a dataset, i am trying to edit a certain Node based upon a criteria, the syntax used to find the node is as follows

Dim nod As XmlNode = xd.SelectSingleNode("/Questions/[ColumnKey='" & row.Item("ColumnKey") & "']")

however it returns an error, can anyone advise where i am going wrong please.

Thanks


- <NewDataSet>
+ <xs:schema id="NewDataSet" xmlns="" xmlns:xs=" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Questions" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="NQAI_Questions">
- <xs:complexType>
- <xs:sequence>
<xs:element name="AuditDate" type="xs:string" minOccurs="0" />
<xs:element name="IDwa" type="xs:string" minOccurs="0" />
<xs:element name="IDbe" type="xs:string" minOccurs="0" />
<xs:element name="ID_Question" type="xs:string" minOccurs="0" />
<xs:element name="Result" type="xs:string" minOccurs="0" />
<xs:element name="Cust" type="xs:string" minOccurs="0" />
<xs:element name="Status_Uploaded" type="xs:string" minOccurs="0" />
<xs:element name="ColumnKey" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <Questions>
<AuditDate>26/07/2010 00:00:00</AuditDate>
<ID_Ward>A</IDwa>
<ID_Bed>B1</IDbe>
<ID_Question>1</ID_Question>
<Result>N/A</Result>
<MPI>772989</Cust>
<Status_Uploaded>No</Status_Uploaded>
<ColumnKey>26/07/2010 00:00:00AB11N/A772989</ColumnKey>
</Questions>
 
It okay i've worked it out, correct syntax was

"/Questions[@ColumnKey='" & row.Item("ColumnKey") & "']
 
Okay this still doesn't work, i've just realised its not finding the node.
I am using the following syntax please advise

Dim nod1 As XmlNode = xd.SelectSingleNode("//NQAI_Questions[@Status_Updated='Yes']")
If nod1 IsNot Nothing Then
nod1.ParentNode.RemoveChild(nod1)
Else
MsgBox("Cant find any")
End If

Thanks for any help
 
[tt] Dim nod1 As XmlNode = xd.SelectSingleNode("/NewDataSet/Questions[Status_Updated='Yes']")[/tt]
 
Hi tsuji,

Thanks for your help, I have changed the code accordingly however it is still returning the node as nothing, please advise further

Thanks again.
 
What is xd? What abstraction/left-out have you done to the document?
 
Hi Xd is the document:-
Dim xd As New XmlDocument()
xd.Load("C:\Dataset.xml")

Is it because I am selecting a single node as opposed to an XMLNodeList?
Basically I am trying to remove items from the xml file that have a Status_Updated of 'Yes'

Thanks
 
Is the <NewDataSet> appeared exactly as you post and it is _the_ root element?
 
Is it Status_Updated or it is Status_Uploaded?
[tt] Dim nod1 As XmlNode = xd.SelectSingleNode("/NewDataSet/Questions[Status_Up[red]loaded[/red]='Yes']")[/tt]
 
Hi the full schema is as below, as mentioned I am trying to remove anything that has a status_uploaded = Yes.
I noticed in the script above i had a type of status_updated as opposed to status_uploaded however changing this still returns nothing, thanks again

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs=" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Questions" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Questions">
<xs:complexType>
<xs:sequence>
<xs:element name="AuditDate" type="xs:string" minOccurs="0" />
<xs:element name="IDWa" type="xs:string" minOccurs="0" />
<xs:element name="IDBe" type="xs:string" minOccurs="0" />
<xs:element name="ID_Question" type="xs:string" minOccurs="0" />
<xs:element name="Result" type="xs:string" minOccurs="0" />
<xs:element name="M" type="xs:string" minOccurs="0" />
<xs:element name="Status_Uploaded" type="xs:string" minOccurs="0" />
<xs:element name="ColumnKey" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Questions>
<AuditDate>27/07/2010 00:00:00</AuditDate>
<IDWa>A</IDWa>
<IDBe>B1</IDBe>
<ID_Question>1</ID_Question>
<Result>N/A</Result>
<M>785487</M>
<Status_Uploaded>No</Status_Uploaded>
<ColumnKey>27/07/2010 00:00:00AB11N/A785487</ColumnKey>
</Questions>
<Questions>
<AuditDate>27/07/2010 00:00:00</AuditDate>
<IDWa>A</IDWa>
<IDBe>B2</IDBe>
<ID_Question>1</ID_Question>
<Result>N/A</Result>
<M>785506</M>
<Status_Uploaded>Yes</Status_Uploaded>
<ColumnKey>27/07/2010 00:00:00AB21N/A785506</ColumnKey>
</Questions>
</NewDataSet>
 
If that is it, the correction of 27 Jul 10 6:55 should work.
 
Hi the actual code i have is

Dim xd As New XmlDocument()
xd.Load("C:\Dataset.xml")
Dim nod1 As XmlNode = xd.SelectSingleNode("/NewDataSet/Questions[Status_Uploaded='Yes']")
If nod1 IsNot Nothing Then
nod1.ParentNode.RemoveChild(nod1)
Else
MsgBox("Cant find any")
End If

But it returns nothing, i'm rather confused :).

Thanks for your help
 
The sub does not interact further with the outside world. That means already that it does and finds the node; otherwise the msgbox will pop up. Would this make it clearer?
[tt]
Dim xd As New XmlDocument()
xd.Load("C:\Dataset.xml")
Dim nod1 As XmlNode = xd.SelectSingleNode("/NewDataSet/Questions[Status_Uploaded='Yes']")
If nod1 IsNot Nothing Then
nod1.ParentNode.RemoveChild(nod1)
[blue]xs.Save("c:\Dataset_out.xml")[/blue]
Else
MsgBox("Cant find any")
End If
[/tt]
 
amendment
There is a typo. The corresponding line should be read like this, sure.
[tt] x[red]d[/red].Save("c:\Dataset_out.xml")[/tt]
 
Hi tsuji, thanks for your help with this, however when i step through the code it goes to else, i.e. the messagebox does pop up, it doesn't actually step into the line nod1.parentnode etc.

Thanks again
 
I don't think so, if you do the rest or things not shown properly.
 
Hi tsuji, thank you for your help, you are correct as you know what you put works. The problem was me in the xml file i didn't have any status updated as 'Yes'

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top