-
Mar 25th, 2020, 07:00 AM
#1
Thread Starter
Lively Member
edit xml document
I have an XML document that I am trying to update specific nodes but the node attributes seem to get in the way. If I leave the attributes, "xmlns:.." and try to search, i get an error that says the node is nothing BUT if I rename the "xmlns:" to "ns", the search works. why is this?? I am trying to use the XMLDocument since once the change has been made, the file has to be moved to another network folder.
If anyone has a better idea than what I am trying to do, please let me know. The full XML is below as is the code I am trying to use.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsd= "http:=//sometext/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<fiAPI xmlns="http://sometextr.com" xmlns:ITI="http://www.Wnet.com/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/xmlenc#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sometext.api.com/API.xsd">
<fiHeader Version="2.2">
<Service Name="TST1337" Version="10.0">
<DateTime>2020-01-09T18:08:02-06:00</DateTime>
<UUID>23e7a103-fa5b-blah-blah-bf18b1068b4b</UUID>
</Service>
<Security>
<AuthenticationMaterial>
<SignedToken>
<EncryptedData>
<CipherData xmlns="http://www.w3.org/2001/04/xmlenc#">
<CipherValue>anencryptedstring</CipherValue>
</CipherData>
</EncryptedData>
</SignedToken>
</AuthenticationMaterial>
<PrincipalID>Prometheus</PrincipalID>
<TrustRelationship xmlns="http://www.Wnet.com/">TrustedUser</TrustRelationship>
</Security>
<Client>
<VendorID>FNB-AK!</VendorID>
<AppID>FNB-AK!INST000</AppID>
<OrgID>00</OrgID>
<SessionID></SessionID>
</Client>
<DataSource>
<URI>TEST</URI>
</DataSource>
</fiHeader>
<Request Echo="false" TypeOfRequest="GetName">
<NameID>5371</NameID>
<GroupName>TEST</GroupName>
<InstNumber>00</InstNumber>
<Sequence>1</Sequence>
<Type>Names</Type>
<Type>AccountNameRelationships</Type>
</Request>
</fiAPI>
</soap:Body>
</soap:Envelope>
Dim MyXML As New XmlDocument()
MyXML.Load("..\..\FNBAXMLFile.xml")
Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/fiAPI/Security/AuthenticationMaterial/SignedToken/EncryptedData/CipherData/CipherValue")
If MyXMLNode IsNot Nothing Then
MyXMLNode.ChildNodes(0).InnerText = "CHANGED"
MyXML.Save("C:\Temp\XmlTest.xml")
Else
MessageBox.Show("node is Nothing")
End If ' Save the Xml.
Last edited by ahbenshaut; Mar 25th, 2020 at 07:39 AM.
-
Mar 25th, 2020, 10:43 AM
#2
Re: edit xml document
It doesn't find it because it's in a namespace. That's what the xmlns does... creates an XML NameSpace... it "works" when you change it because you break the rules and you break it out of the namespace. Fortunately you don't need to do that (nor should you) ... what you need to do is add a NamespaceManager to add the xsi namespace - I don't thinks its necessary to add xsd as that's by default, try it without it, if it still fails, then add it too - once you have the namespace(s) added, to the manager and the manager linked to the document, you can search your nodes just like you're trying to do.
-tg
-
Mar 25th, 2020, 11:32 AM
#3
Thread Starter
Lively Member
Re: edit xml document
Originally Posted by techgnome
It doesn't find it because it's in a namespace. That's what the xmlns does... creates an XML NameSpace... it "works" when you change it because you break the rules and you break it out of the namespace. Fortunately you don't need to do that (nor should you) ... what you need to do is add a NamespaceManager to add the xsi namespace - I don't thinks its necessary to add xsd as that's by default, try it without it, if it still fails, then add it too - once you have the namespace(s) added, to the manager and the manager linked to the document, you can search your nodes just like you're trying to do.
-tg
hmmm
After some moving some code around and with some help, I was able to get it to work by using:
Code:
Dim MyXML As New XmlDocument()
MyXML.Load("..\..\FNBAXMLFile.xml")
txtResponse.Text = MyXML.OuterXml
Dim node As XmlNodeList = MyXML.GetElementsByTagName("CipherValue")
If node IsNot Nothing Then
node(0).InnerText = "ALL RIGHTY THEN"
MyXML.Save("C:\Temp\XmlTest.xml")
Else
MessageBox.Show("node is Nothing")
End If
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|