Archive for the ‘XML’ Category

How to detemine namespaces used by the Xml Document

I have been browsing on web on how to extract / determine the namespaces in the xml document given that the xml documetns are coming from different clients and there’s no standard content format, it took me 2 days browsing to find the exact answer but no luck, what i found was only how to add/remove. So, what i did was experimenting / exploring the XmlDocument Object on my own, and fortunately I found the answer in less than 30 minutes.

Here’s the sample script on vb.net

‘Declare a variables

Dim nm as XmlNamespaceManager

Dim doc as new XmlDocument()

Dim root as XmlNode

doc.load(”c:\xml\test.xml”) ‘ xml path

nm = new XmlNamespaceManager(doc.NameTable);

Here’s the tricky part, you need to extract the attributes of the root document and iterate them.

root = doc.DocumentElement  ’get the root document

for i as integer =0 to root.Attributes.count -1

if roo.Attributes(i).Prefix.tolower() = “xmlns” then   ‘check if namespace

nm.AddNamespace (roo.Attributes(i).LocalName, roo.Attributes(i).Value)

endif

next

That’s it..

, ,

No Comments


Sum with empty element on XPath using .Net

When using sum function on XPath using .net you will get errors “Nan” if the node is empty because it use for numbers only. So, you need to select the nodes/elements that are not empty.

sum(//Quantity[node()])

, ,

No Comments


How to Create Schema from XML in .net

You will use the xsd.exe to create an schema from xml.

Process.start(”xsd.exe”, “xmlfile”)

, , , ,

No Comments


How to Insert Xml Node from One document to another XML Document in vb.net

If you want to insert xmlnode from one document to another, you have to import the xmlnode. 

dim xmlDoc01 as XMLDocument

dim xmlDoc02 as XMLDocument

private sub InsertNod()  ’insert xmlnode from xmlDoc01 to xmlDoc02

{

xmldoc01.AppendChild(xmlDoc01.ImportNode(xmlDoc01.ChildNodes(0), true))

}

, , ,

No Comments



SetPageWidth