up  好像在C#帖子里头看不见

解决方案 »

  1.   

    如何采用XMLDocument实现如下的XML文件?<?xml version="1.0" standalone="yes"?>
    <XMLSchema1 xmlns="http://tempuri.org/XMLSchema1.xsd">
      <xs:schema id="XMLSchema1" targetNamespace="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="http://tempuri.org/XMLSchema1.xsd" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
        <xs:element name="XMLSchema1" msdata:IsDataSet="true" msdata:Locale="zh-CN">
          <xs:complexType>
            <xs:choice maxOccurs="unbounded">
              <xs:element name="Bay">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="BayCode" type="xs:string" minOccurs="0" />
                    <xs:element name="MaxLayer" type="xs:string" minOccurs="0" />
                    <xs:element name="MaxRow" type="xs:string" minOccurs="0" />
                    <xs:element name="BoardUpLayer" type="xs:string" minOccurs="0" />
                    <xs:element name="BoardDownLayer" type="xs:string" minOccurs="0" />
                    <xs:element name="BayDetail" form="unqualified">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="LayerID" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="RowID" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="LayerCode" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="RowCode" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="ContainerNumber" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="ContainerSize" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="ContainerType" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="PortOfLoad" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="PortOfDischarge" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="PortOfOrder" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="CellColor" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="IsCurrentPort" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="TeuOrder" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="IsTranslate" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="ContainerID" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="BayPlaceCode" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="BayType" form="unqualified" type="xs:string" minOccurs="0" />
                          <xs:element name="IsExistBay" form="unqualified" type="xs:string" minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:schema>
      <Bay>
        <BayCode>001</BayCode>
        <MaxLayer>5</MaxLayer>
        <MaxRow>5</MaxRow>
        <BoardUpLayer>3</BoardUpLayer>
        <BoardDownLayer>2</BoardDownLayer>
        <BayDetail xmlns="">
          <LayerID>1</LayerID>
          <RowID>1</RowID>
          <LayerCode>86</LayerCode>
          <RowCode>04</RowCode>
          <ContainerNumber />
          <ContainerSize>20</ContainerSize>
          <ContainerType />
          <PortOfLoad />
          <PortOfDischarge />
          <PortOfOrder />
          <CellColor>-657931</CellColor>
          <IsCurrentPort>0</IsCurrentPort>
          <TeuOrder>0</TeuOrder>
          <IsTranslate>0</IsTranslate>
          <ContainerID>0</ContainerID>
          <BayPlaceCode>0010486</BayPlaceCode>
          <BayType>1</BayType>
          <IsExistBay>0</IsExistBay>
        </BayDetail>
        <BayDetail xmlns="">
          <LayerID>2</LayerID>
          <RowID>1</RowID>
          <LayerCode>86</LayerCode>
          <RowCode>02</RowCode>
          <ContainerNumber />
          <ContainerSize>20</ContainerSize>
          <ContainerType />
          <PortOfLoad />
          <PortOfDischarge />
          <PortOfOrder />
          <CellColor>-657931</CellColor>
          <IsCurrentPort>0</IsCurrentPort>
          <TeuOrder>0</TeuOrder>
          <IsTranslate>0</IsTranslate>
          <ContainerID>0</ContainerID>
          <BayPlaceCode>0010286</BayPlaceCode>
          <BayType>1</BayType>
          <IsExistBay>0</IsExistBay>
        </BayDetail>
        <BayDetail xmlns="">
          <LayerID>3</LayerID>
          <RowID>1</RowID>
          <LayerCode>86</LayerCode>
          <RowCode>00</RowCode>
          <ContainerNumber />
          <ContainerSize>20</ContainerSize>
          <ContainerType />
          <PortOfLoad />
          <PortOfDischarge />
          <PortOfOrder />
          <CellColor>-657931</CellColor>
          <IsCurrentPort>0</IsCurrentPort>
          <TeuOrder>0</TeuOrder>
          <IsTranslate>0</IsTranslate>
          <ContainerID>0</ContainerID>
          <BayPlaceCode>0010086</BayPlaceCode>
          <BayType>1</BayType>
          <IsExistBay>0</IsExistBay>
        </BayDetail>
      

  2.   

    XmlNode nodeBay = doc.CreateElement("Bay");XmlNode nodeBayCode = doc.CreateNode(XmlNodeType.Element,"BayCode", "");
    //...............................
    nodeBayCode.InnerText = "";
    //...............................nodeBay.AppendChild(nodeBayCode);
    //...............................for (........)
    {
    XmlNode nodeLayerID = doc.CreateNode(XmlNodeType.Element,"LayerID", ""); XmlNode nodeBayDetail=doc.CreateElement("BayDetail");
    nodeLayerID.InnerText = "";

    nodeBayDetail.AppendChild(nodeLayerID); nodeBay.AppendChild(nodeBayDetail);
    }
    doc.DocumentElement.AppendChild(nodeBay);
    doc.Save(@"E:\test.xml");
      

  3.   

    DSTest.Tables["BayDetail"].Rows.Count=0;结构应该读取出来了,不然会抛出null异常。在cf没用过DataSet的GetXml()方法读取xml,XMLDocument不支持xpath也很难用,但如果你子想写一个上面那样格式的文件,直接用StreamWriter存储成xml不就行了吗。
      

  4.   

    结构确实读出来了
    问题是由于DataSet无法直接读取出来,想用XMLDocument试试看。CF中还是支持部分的XMLDocument的
      

  5.   

    DSTest.Tables["Bay"].Rows.Count>0,说明正常
    单单里头的childs不行
      

  6.   

    XmlNode nodeBay = doc.CreateElement("Bay");XmlNode nodeBayCode = doc.CreateNode(XmlNodeType.Element,"BayCode", "");
    //...............................
    nodeBayCode.InnerText = "";
    //...............................nodeBay.AppendChild(nodeBayCode);
    //...............................for (........)
    {
    XmlNode nodeLayerID = doc.CreateNode(XmlNodeType.Element,"LayerID", ""); XmlNode nodeBayDetail=doc.CreateElement("BayDetail");
    nodeLayerID.InnerText = "";

    nodeBayDetail.AppendChild(nodeLayerID); nodeBay.AppendChild(nodeBayDetail);
    }
    doc.DocumentElement.AppendChild(nodeBay);
    doc.Save(@"E:\test.xml");
      

  7.   

    晕 savagewang1978(遛鎏) 你都已经有四个裤衩了,怎么还老是抄别人的帖子来回帖阿?更何况还在同一个帖子。如果给一个UP我还会感激你。