Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Import XML file without stylesheet

Import XML file without stylesheet

Scheduled Pinned Locked Moved C#
xmlquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Richard Berry100
    wrote on last edited by
    #1

    Hi I need to populate a datatable with two fields from an xml file. and The file was obtained from a report that opens in a web browser, and the file saved from there.

    DataTabel.ReadXml(XMLFilename)

    fails (complains about the ':' character in Line 2 of the xml file.) I thought about using something like below, since I do have a complete list of the in another table, but the is not a child node of , and this also fails (complains about the ':' character in Line 2 of the xml file.)

    public string GetKeyValue(string key)
    {
    System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
    xd.Load(_XMLFileName);
    System.Xml.XmlNode Node = xd.DocumentElement.SelectSingleNode("/REPORTTABLE/REPORTTABLEDETAILS/PARTNUM add[@key=\"" + key + "\"]");

            if ((Node != null))
            {
                return Node.Attributes.GetNamedItem("value").Value;
            }
            else
            {
                return null;
            }
        }
    

    Any idea how I can get a list of PARTNUM with the corresponding ACTUALQTYNUM?

    2014/07/11 13:36:44
    Fujiuser
    Week_23_2014

    260-C536000-PACE - Top_TLine 1 / Line 1 / Top / 1
    260-C536000-PACE - Top_BLine 2 / VEK Line 2 / Bottom / 1
    38
    938-1030507938-1030507938-1030507
    2
    2
    0
    4
    6249
    6245

    948-1025627948-1025627948-1025627
    2
    1
    -1
    40
    6720
    6680

    L 1 Reply Last reply
    0
    • R Richard Berry100

      Hi I need to populate a datatable with two fields from an xml file. and The file was obtained from a report that opens in a web browser, and the file saved from there.

      DataTabel.ReadXml(XMLFilename)

      fails (complains about the ':' character in Line 2 of the xml file.) I thought about using something like below, since I do have a complete list of the in another table, but the is not a child node of , and this also fails (complains about the ':' character in Line 2 of the xml file.)

      public string GetKeyValue(string key)
      {
      System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
      xd.Load(_XMLFileName);
      System.Xml.XmlNode Node = xd.DocumentElement.SelectSingleNode("/REPORTTABLE/REPORTTABLEDETAILS/PARTNUM add[@key=\"" + key + "\"]");

              if ((Node != null))
              {
                  return Node.Attributes.GetNamedItem("value").Value;
              }
              else
              {
                  return null;
              }
          }
      

      Any idea how I can get a list of PARTNUM with the corresponding ACTUALQTYNUM?

      2014/07/11 13:36:44
      Fujiuser
      Week_23_2014

      260-C536000-PACE - Top_TLine 1 / Line 1 / Top / 1
      260-C536000-PACE - Top_BLine 2 / VEK Line 2 / Bottom / 1
      38
      938-1030507938-1030507938-1030507
      2
      2
      0
      4
      6249
      6245

      948-1025627948-1025627948-1025627
      2
      1
      -1
      40
      6720
      6680

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See http://www.w3.org/TR/xml-stylesheet/[^].

      R 1 Reply Last reply
      0
      • L Lost User

        See http://www.w3.org/TR/xml-stylesheet/[^].

        R Offline
        R Offline
        Richard Berry100
        wrote on last edited by
        #3

        Thanks for your reply Richard. From W3.org it seems the file is possibly not 100% compliant

        xml:stylesheet

        should be

        xml-stylesheet

        But even so, I eventually got hold of the stylesheet which did not have any Schema info. Also tried DataSet.ReadXml as many posts on the net suggested where a schema was not available with no luck. Ended up reading the file with StreamReader.ReadLine and picking out the values I needed with SubString(...)

        B 1 Reply Last reply
        0
        • R Richard Berry100

          Thanks for your reply Richard. From W3.org it seems the file is possibly not 100% compliant

          xml:stylesheet

          should be

          xml-stylesheet

          But even so, I eventually got hold of the stylesheet which did not have any Schema info. Also tried DataSet.ReadXml as many posts on the net suggested where a schema was not available with no luck. Ended up reading the file with StreamReader.ReadLine and picking out the values I needed with SubString(...)

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Having to deal with defective XML files is always fun... My 5 for seeing that little difference. Alternatively to your solution, write the file back line by line, just omitting the "bad" line. With that file, some tools could generate classes for its content, and thus making the access to the properties easier. The Japanese encoding could cause some more fun later on, be prepared for that.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups