I have a file like this <ufile.io/g8dy86x0>
I'd like remove signature.
I try this code but doesn't work
Dim doc As XmlDocument = New XmlDocument
doc.Load(_filename)
Dim rnode As XmlNode = doc.SelectSingleNode("Signature")
doc.OwnerDocument.DocumentElement.RemoveChild(rnode)
What should i try ?
Related
How can i read attribute value of a xml.
I have this below xml and i am working with windows forms vb.net
I tried something like this below but does not work. I want to read connection string value
Dim xe As XElement = XElement.Load("..\\..\\KMMiddleTier.xml")
Dim name = From nm In xe.Elements("ConnectionKey") Where nm.Element("ConnectionKey").Attribute("Key") = "DB_DEV" Select nm.Element("ConnectionKey").Attribute("ConnectionString").Value.FirstOrDefault()
Dim xmlDoc as XMLDocument
Dim xmlNodeList As XmlNodeList = xmlDoc.SelectNodes("/KMMiddleTierSecurity/ConnectionKeys/ConnectionKey")
Dim strConnectionKey As String = xmlNodeList.Item(0).Attributes("ConnectionString").Value''''
This might help.
I am trying to do some XSLT transformation, to convert an XML to XML, using the following lines of code. When i try to create an XMLDocument object from the transformed XML i am getting an error
Data at the root level is invalid. Line 1, position 1.
Dim outputXML As New XmlDocument
Dim stream As New MemoryStream
Dim writer As XmlTextWriter = New XmlTextWriter(stream, System.Text.UnicodeEncoding.UTF8)
Dim navigator As XPathNavigator = illustratePlusXML.CreateNavigator()
Dim transormer As XslCompiledTransform = New XslCompiledTransform()
transormer.Load(ConfigurationManager.AppSettings("XSLT_File_Path"))
transormer.Transform(navigator, Nothing, writer)
Dim output As String = System.Text.UnicodeEncoding.UTF8.GetString(stream.ToArray())
outputXML.LoadXml(output)
Return outputXML
I could find a special character(square box), i persume this is causing the error. attached snapshot of the output xml. Can somebody please suggest ?
If you want to populate an XmlDocument as the result of an XSLT transformation then simply do
Dim resultDoc As New XmlDocument()
Using xw As XmlWriter = resultDoc.CreateNavigator().AppendChild()
Dim navigator As XPathNavigator = illustratePlusXML.CreateNavigator()
Dim transormer As XslCompiledTransform = New XslCompiledTransform()
transormer.Load(ConfigurationManager.AppSettings("XSLT_File_Path"))
transormer.Transform(navigator, Nothing, xw)
xw.Close()
End Using
There is no need to use a MemoryStream. If you really think you need to use a MemoryStream then make sure you reset its Position to 0 before calling the Load method.
I have some trouble creating my XmlDocument class. This is what I've tried to do:
Dim myDoc = New XmlDocument()
Dim docType As XmlDocumentType = myDoc.CreateDocumentType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
myDoc.XmlResolver = Nothing
myDoc.AppendChild(docType)
Dim xmldecl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", Encoding.GetEncoding("ISO-8859-15").BodyName, "yes")
Dim root As XmlElement = myDoc.CreateElement("RootElement")
myDoc.AppendChild(root)
myDoc.InsertBefore(xmldecl, root)
This will result in error: Cannot insert the node in the specified location. Line throwing this error is myDoc.InsertBefore(xmldecl, root)
Just cannot figure out this. Which order should I insert these elements? I've tried different orders but I think I'm just doing something totally wrong and this shouldn't even work in the first place :) But then how to do this?
This works for me:
Dim myDoc As New XmlDocument()
Dim xmldecl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", Encoding.GetEncoding("ISO-8859-15").BodyName, "yes")
myDoc.AppendChild(xmldecl)
Dim docType As XmlDocumentType = myDoc.CreateDocumentType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
myDoc.XmlResolver = Nothing
myDoc.AppendChild(docType)
Dim root As XmlElement = myDoc.CreateElement("DtdAttribute")
myDoc.AppendChild(root)
Note that the root element name must be the same as the name parameter given to XmlDocument.CreateDocumentType.
You may find, however, that for building an XML document from scratch like this, it's easier to just use the XmlTextWriter:
Using writer As New XmlTextWriter("C:\Test.xml", Encoding.GetEncoding("ISO-8859-15"))
writer.WriteStartDocument()
writer.WriteDocType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
writer.WriteStartElement("DtdAttribute")
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
Dim codice As String
Dim doc As New HtmlDocument
Dim coll As HtmlNodeCollection
Dim node As HtmlNode
Dim nuovo As HtmlNode
codice = "<li>� " + T_ClasNome.Text + "</li>"
doc.Load("classifica.html")
coll = doc.GetElementbyId("subnavi").SelectNodes("ul")
node = coll.Last
nuovo = HtmlNode.CreateNode(codice)
node.AppendChild(nuovo)
doc.Save("classifica.html")
This add a line of HTML in "codice" at a specified position, but I've noticed that everytime it writes to my HTML file it doesn't go to a new line, so it will write:
**(1st item)**<li>� 3 Class</li>**(2nd item)**<li>� classificagioca.0tori.htm</li>
How can I go to a new line in the HTML file for a more confortable view?
In C# you can try something like this.
var newLineNode = HtmlNode.CreateNode("\r\n");
var nuovo = HtmlNode.CreateNode(codice);
node.AppendChild(newLineNode);
node.AppendChild(nuovo);
node.AppendChild(newLineNode);
I am generating this XML using the serializer in VB.net as shown below
Dim string_writer As New StringWriter()
Dim serializer As New XmlSerializer(GetType(MyClass))
serializer.Serialize(string_writer, addr)
txttest.Text = string_writer.ToString()
though it is returning XML, I see xmlns="http://tempuri.org/ in all the elements, is there anyway I hide this one.
Sure - just pass the default namespace you want to use to the constructor of your XmlSerializer:
Dim string_writer As New StringWriter()
Dim serializer As New XmlSerializer(GetType(MyClass), "")
serializer.Serialize(string_writer, addr)
txttest.Text = string_writer.ToString()
That should do the trick.