You must Sign In to post a response.
  • Category: XML

    C# How read xml, XML Syntax when Using Colon (:), in Tags

    c# How read xml, XML Syntax when Using Colon (:) in Tags

    i want to read this

    <?xml version="1.0" encoding="utf-8"?>
    <feed xml:base="" xmlns="" xmlns:d="" xmlns:m="">
    <title type="text">Ships</title>
    <link rel="self" title="Ships" href="Ships" />
    <category term="Portal_Dev_TestDbModel.Ship" scheme="" />
    <link rel="edit" title="Ship" href="Ships(599)" />
    <link rel="" type="application/atom+xml;type=entry" title="Company" href="Ships(599)/Company" />
    <link rel="" type="application/atom+xml;type=feed" title="ShipPivots" href="Ships(599)/ShipPivots" />
    <link rel="" type="application/atom+xml;type=feed" title="Voyages" href="Ships(599)/Voyages" />
    <title />
    <name />
    <content type="application/xml">
    <d:Id m:type="Edm.Int32">599</d:Id>
    <d:Name>Jag Lok</d:Name>
    <d:CompanyId m:type="Edm.Int32">80</d:CompanyId>
    <d:SerieId m:type="Edm.Int32" m:null="true" />
    <d:CargoId m:type="Edm.Int32">2</d:CargoId>

  • #754816

    can u try in this way, i thin its helpfor uu.
    xml are like:

    <rss xmlns:g="" xmlns:receipt="urn:receipt">
    <g:google_product_category />

    2: In C#:

    XNamespace g = "";
    XElement rss = XElement.Parse(@"<rss xmlns:g="""" xmlns:receipt=""urn:receipt""> </rss>");
    rss.Add(new XElement("channel",
    new XElement("item",
    new XElement(g + "id"),
    new XElement(g + "google_product_category"),
    new XElement(g + "image_link"),
    new XElement(g + "image_link")


  • #754858

    You can read using XML reader tag by tag.

    if you want to read using XPATH that is also possible.

    sing System;
    using System.Xml;

    namespace ReadXML
    class XMLRead
    static void Main(string[] args)
    XmlTextReader reader = new XmlTextReader ("Anil.xml");
    while (reader.Read())
    switch (reader.NodeType)
    case XmlNodeType.Element:
    Console.Write("Element: " + reader.Name);
    case XmlNodeType.Text:
    Console.WriteLine ("Value:" + reader.Value);
    case XmlNodeType.EndElement:
    Console.Write("Last Element" + reader.Name);

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #755775
    The easiest and fastest way to get <m:properties> node and its subnodes is to use System.Xml.XPath:

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.Load(yourFileName); // or: xmlDocument.LoadXml(yourXmlString);

    // this expression below gets all "properties" nodes which parent "content" has an attribute "type" with a value = "application/xml":
    string xpathExpression = "/feed/entry/content[@type='application/xml']/m:properties";

    // to recognise the xml namespaces
    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
    namespaceManager.AddNamespace("m", "");

    // get the node
    XmlNodeList propertiesNodes = xmlDocument.SelectNodes(xpathExpression, namespaceManager);

    // now get the subnodes...

  • Sign In to post your comments