2012-04-05 60 views
1

这是我得到的012ml的输出结果为Infragistics ultrawebtree的xml。我正在使用它创建另一个具有相同结构的Infragistics ultrawebtree。但在这里我不想要<Url>something.aspx..</Url>。我希望这是这样的<Url><\Url>。所以我如何能够删除。这我得到作为一个字符串。所以我用Regex.Replace()。但它会适用于某些条件,但在某些情况下,它会通过删除一些xml标记来破坏xml,并且xml由于缺少标记而变得无效。 我用这个表达式<Url>\S*</Url>来避免Url的内容。任何帮助将非常有帮助。提前致谢。从以下XML中删除节点。

<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
- <InfragisticsServerTree XmlVersion="1.0"> 
    - <uwtModule> 
    - <ProjectProperties> 
     <ComponentTarget>ClassicTree</ComponentTarget> 
     <BrowserTarget>Auto</BrowserTarget> 
    </ProjectProperties> 
    - <TreeProperties> 
     <MaxDataBindDepth>-1</MaxDataBindDepth> 
     <Name>uwtModule</Name> 
     <Indentation>20</Indentation> 
     <SubMenuImage>igNone</SubMenuImage> 
     <LoadOnDemandPrompt> 
     <b>Loading...</b> 
     </LoadOnDemandPrompt> 
     <ExpandAnimation>Decelerate</ExpandAnimation> 
     <ExpandOnClick>false</ExpandOnClick> 
     <CompactRendering>false</CompactRendering> 
     <RenderAnchors>false</RenderAnchors> 
     - <Style> 
     <ForeColor>-16777216</ForeColor> 
     <BorderColor>-4144960</BorderColor> 
     <BorderStyle>None</BorderStyle> 
     <BorderWidth>1px</BorderWidth> 
     - <Font> 
      <Name>Arial</Name> 
      - <Names> 
      <Name>Arial</Name> 
      </Names> 
      <Size>11px</Size> 
     </Font> 
     <Height>425px</Height> 
     <Width>97%</Width> 
     - <Padding> 
      <Top>5px</Top> 
      <Left>5px</Left> 
      <Right>5px</Right> 
      <Bottom>5px</Bottom> 
     </Padding> 
     </Style> 
     - <SelectedNodeStyle> 
     <BackColor>-2894893</BackColor> 
     <ForeColor>-16777216</ForeColor> 
     - <Padding> 
      <Top>2px</Top> 
      <Left>2px</Left> 
      <Right>2px</Right> 
      <Bottom>2px</Bottom> 
     </Padding> 
     </SelectedNodeStyle> 
    </TreeProperties> 
    <Styles /> 
    - <Levels> 
     - <Level> 
     <Number>0</Number> 
     </Level> 
    </Levels> 
- <Nodes> 
    - <Node> 
    <Text>123</Text> 
    <Url>ModuleEdit.aspx?ModuleID=965</Url> 
    <Target>main</Target> 
    <Tag>965</Tag> 
    <Title>AccptChangesPerfPM</Title> 
    <Expanded>true</Expanded> 
    - <Nodes> 
     - <Node> 
     <Text>111</Text> 
     <Url>123.aspx?e=965 </Url> 
     <Target>main</Target> 
     <Tag>TL_-99999</Tag> 
     </Node> 
     - <Node> 
     <Text>werrv</Text> 
     <Url>1dfee.aspx?qwe=9er65</Url> 
     <Target>main</Target> 
     <Tag>12DDfe</Tag> 
     </Node> 
     - <Node> 
     <Text>q2233</Text> 
     <Target>main</Target> 
     <Tag>TL_1015</Tag> 
     <Title>Topic_1</Title> 
     <ShowExpand>true</ShowExpand> 
     - <Nodes> 
      - <Node> 
      <Text>T1</Text> 
      <Url>w3345_954y65.aspx?ID=965er</Url> 
      <Target>main</Target> 
      - <Style> 
       <ForeColor>-16777216</ForeColor> 
      </Style> 
      <Tag>82355</Tag> 
      <Title>T1</Title> 
      </Node> 
      - <Node> 
      <Text>T2</Text> 
      <Url>23_7811.aspx?ID=3u65</Url> 
      <Target>main</Target> 
      - <Style> 
       <ForeColor>-16777216</ForeColor> 
      </Style> 
      <Tag>82356</Tag> 
      <Title>T2</Title> 
      </Node> 
      - <Node> 
      <Text>T3</Text> 
      <Url>we456_9.aspx?ID=4r56</Url> 
      <Target>main</Target> 
      - <Style> 
       <ForeColor>-16777216</ForeColor> 
      </Style> 
      <Tag>82357</Tag> 
      <Title>T3</Title> 
      </Node> 
     </Nodes> 
     </Node> 
    </Nodes> 
    </Node> 
</Nodes> 
    </uwtModule> 
</InfragisticsServerTree> 
+0

更改为Xml类会更容易。 您是否考虑过这种替代方案? – 2012-04-05 14:37:14

+0

我试过Regex,xml到DataSet。但我不知道如何使用XMLDoc和XML。我也试过,但将会在下。 的子节点。那么我将如何查询? – kbvishnu 2012-04-05 14:39:58

回答

4

我的建议是忽略正则表达式。

Go对于VB的XML类来从文件中读取, 然后与节点列表和节点一起工作。

这里有一些链接,让你开始:

Create XML in VB#

Modify XML literals in VB#

Samples of multiple actions on XML files in VB#

[VB.NET] XML - Create and Merge Files. Edit, Add and Delete Nodes.

在你上面的链接会发现重文档和示例如何打开,编辑,创建,合并。

下面是一个如何做你所问以上︰ 但公正的警告:这是C#你需要使用上面的链接来转换,因为我不是很多的VB.Net开发人员

string path = "./"; //your own path 
string name = "Tempo"; //filename 
XmlDocument f = new XmlDocument(); 
f.Load(path + name + ".xml"); 
XmlNodeList a = f.GetElementsByTagName("Url"); 
for (int i = 0; i < a.Count; i++) 
{ 
    a[i].InnerText = "" //This had the data inside <Url>...</Url> 
} 
    f.Save(path+name); //Edited to add the save 
+0

感谢它的作品..我可以知道表演效果吗? – kbvishnu 2012-04-05 16:19:33

+0

打开一个文件,将它加载到一个结构搜索它适应保存完整的文件从不是一个轻量级的操作,当XML很大时。 但我不认为与正则表达式更简单,但我没有数据备份我的意见。 – 2012-04-05 16:36:42

+0

我不保存到文件。我正在用一个字符串处理它。 – kbvishnu 2012-04-05 16:47:17