Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从xml中的节点中删除重复的命名空间属性?_Xml_Vb.net_Xml Parsing_Xmlreader_Xmlwriter - Fatal编程技术网

如何从xml中的节点中删除重复的命名空间属性?

如何从xml中的节点中删除重复的命名空间属性?,xml,vb.net,xml-parsing,xmlreader,xmlwriter,Xml,Vb.net,Xml Parsing,Xmlreader,Xmlwriter,我有两个巨大的1 gb xml文件。它们都有相同的结构。我正在尝试合并它们。 脚本使用xmltextreader和xmltextwriter。除了将命名空间复制到多个节点外,它工作正常。我读了很多博客和文件,但找不到合适的解决办法。 任何想法或帮助都是值得的 对于测试,我只是从下面的xml中读取并写入新的xml文件。 在输出文件title节点中有这个额外的名称空间,这是我不想要的 下面是我的示例xml文件 <?xml version="1.0" encoding="utf-8"?>

我有两个巨大的1 gb xml文件。它们都有相同的结构。我正在尝试合并它们。 脚本使用xmltextreader和xmltextwriter。除了将命名空间复制到多个节点外,它工作正常。我读了很多博客和文件,但找不到合适的解决办法。 任何想法或帮助都是值得的

对于测试,我只是从下面的xml中读取并写入新的xml文件。 在输出文件title节点中有这个额外的名称空间,这是我不想要的

下面是我的示例xml文件

<?xml version="1.0" encoding="utf-8"?>
<records xmnls:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sample.xsd">
<record category="xyz" editor="" entered="sdsd" sub-category="sds" uid="ds" updated="sd-07-15">
    <person ssn="" e-i="M">
      <title xsi:nil="true"/>
      <position>abcd</position>
      <names>
        <first_name>xyz</first_name>
        <last_name>xyz</last_name>
      </names>
    </person>
</record>
<record category="xyz" editor="" entered="sdsd" sub-category="sds" uid="ds" updated="sd-07-15">
    <person ssn="" e-i="M">
      <title xsi:nil="true"/>
      <position>abcd</position>
      <names>
        <first_name>xyz</first_name>
        <last_name>xyz</last_name>
      </names>
    </person>
</record>
</records>

my code is as below

        Public Sub Main()
        Dim DownloadPEPLocation As String = Dts.Variables("xyz").Value
        Dim ACTIMIZESource As String = Dts.Variables("ACTIMIZESource").Value
        Dim PEPTextReader As Xml.XmlTextReader
        Dim Destination As Xml.XmlTextWriter
        Destination = New Xml.XmlTextWriter(ACTIMIZESource, System.Text.Encoding.UTF8)
        Destination.Formatting = Formatting.Indented
        Destination.Namespaces = True

        PEPTextReader = New XmlTextReader(DownloadPEPLocation)
        PEPTextReader.WhitespaceHandling = WhitespaceHandling.None

        Destination.WriteStartDocument()
        Destination.WriteStartElement("records")

        Destination.WriteAttributeString("xmnls:xsi", "http://www.w3.org/2001/XMLSchema-instance")
        Destination.WriteAttributeString("xsi:noNamespaceSchemaLocation", "world-check.xsd")

        Dim PEPreading As Boolean = PEPTextReader.Read()
        Do While (PEPreading)
            If (PEPTextReader.NodeType = XmlNodeType.Element And PEPTextReader.LocalName = "record") Then
                Destination.WriteNode(PEPTextReader, True)
                Destination.Flush()
            Else
                PEPreading = PEPTextReader.Read()
            End If
        Loop

        Destination.WriteEndElement()
        Destination.WriteEndDocument()
        Destination.Close()
        PEPTextReader.Close()


Output is look like this.

<?xml version="1.0" encoding="utf-8"?>
<records xmnls:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sample.xsd">
<record category="xyz" editor="" entered="sdsd" sub-category="sds" uid="ds" updated="sd-07-15">
    <person ssn="" e-i="M">
      <title xsi:nil="true" **xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"** />
      <position>abcd</position>
      <names>
        <first_name>xyz</first_name>
        <last_name>xyz</last_name>
      </names>
    </person>
</record>
<record category="xyz" editor="" entered="sdsd" sub-category="sds" uid="ds" updated="sd-07-15">
    <person ssn="" e-i="M">
      <title xsi:nil="true" **xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"** />
      <position>abcd</position>
      <names>
        <first_name>xyz</first_name>
        <last_name>xyz</last_name>
      </names>
    </person>
</record>
</records>

`

abcd
xyz
xyz
abcd
xyz
xyz
我的代码如下
公用分干管()
Dim DownloadPEPLocation作为字符串=Dts.Variables(“xyz”).Value
Dim ActivizeSource As String=Dts.Variables(“ActivizeSource”).Value
将PEPTextReader设置为Xml.XmlTextReader
Dim目标为Xml.XmlTextWriter
Destination=New Xml.XmlTextWriter(ACTIMIZESource,System.Text.Encoding.UTF8)
Destination.Formatting=Formatting.Indented
Destination.namespace=True
PEPTextReader=新的XmlTextReader(下载PepLocation)
PEPTextReader.WhitespaceHandling=WhitespaceHandling.None
Destination.WriteStartDocument()
Destination.WriteStarteElement(“记录”)
Destination.WriteAttributeString(“xmnls:xsi,”http://www.w3.org/2001/XMLSchema-instance")
Destination.WriteAttributeString(“xsi:noNamespaceSchemaLocation”、“world check.xsd”)
将PEPreading设置为布尔值=PEPTextReader.Read()
边做边读(打气)
如果(PEPTextReader.NodeType=XmlNodeType.Element和PEPTextReader.LocalName=“record”),则
Destination.WriteNode(PEPTextReader,True)
Destination.Flush()
其他的
PEPreading=PEPTextReader.Read()
如果结束
环
Destination.WriteEndElement()
Destination.WriteEndDocument()文件
Destination.Close()
PEPTextReader.Close()
输出是这样的。
abcd
xyz
xyz
abcd
xyz
xyz
`

@Tapan:根据您的输入和输出示例,在
根元素的
xmlns
属性上,似乎有两个字母被不小心地转置了:

<records xmnls:xsi="http://www.w3.org/2001/XMLSchema-instance"
         ^^^^^

感谢您的更新。我做了一些修改,但仍然不起作用。你知道如何删除重复的名称空间吗。