현재 문제가 있습니다. 문제가 있습니다. C#에서 xml 파일을로드하고 일부 노드를 제거하고 일부 노드를 추가합니다. 지금 문제는 XML 파일에서 제거를하고있을 때 자동으로 생성 된 빈 줄이 있으므로이 줄을 제거하고 싶습니다. 내가 XML의 부모 노드에 일부 노드를 추가 할 때XML 문서에서 빈 줄을 제거하십시오.
는 그리고 난 각각의 종료 태그 예를 들어
의 새로운 라인을합니다. 내 XML 파일입니다
<intro id="S0001">
<title>Introduction Title</title>
<para>This is a paragraph. Note that paragraphs can contain other block–level objects, such as lists, as well as directly containing text.</para>
<para>The introduction can contain all of the text objects that a section can contain, except that it cannot be divided into parts, sections and sub–sections.</para>
<para>The introduction can contain tables:</para>
</intro><part>
<no>Part A</no> Article Structure <sup>(Part Title)</sup><section1 id="S0002">`enter code here`
<no>Sect 1</no>
<title>First Section in Part 1 <sup>(Section 1 Title)</sup></title>
<shortsectionhead>Short Section Header</shortsectionhead>
<para>This is a section in the first part of the article.</para>
</section1><section1 id="S0003">
코드 :
XmlNode partNnode = xmlDoc.SelectSingleNode("//part");
XmlNode introNode=xmlDoc.SelectSingleNode("//intro");
XmlDocumentFragment newNode=xmlDoc.CreateDocumentFragment();
newNode.InnerXml=partNnode.OuterXml;
introNode.ParentNode.InsertAfter(newNode,introNode);
partNnode.ParentNode.RemoveChild(partNnode);
partNnode = xmlDoc.SelectSingleNode("//part");
nodeList = xmlDoc.SelectNodes("//section1");
foreach (XmlNode refrangeNode in nodeList)
{
newNode=xmlDoc.CreateDocumentFragment();
newNode.InnerXml=refrangeNode.??OuterXml;
partNnode.AppendChild(newNode);
}
당신이 다음 XML 형식이 올바르게되어야로드 및 C#과 XML 파일을 저장하면 (나에게 사전
지금까지 시도한 코드를 게시 할 수 있습니까? –
XmlNode partNnode = xmlDoc.SelectSingleNode ("// part"); XmlNode introNode = xmlDoc.SelectSingleNode ("// intro"); XmlDocumentFragment newNode = xmlDoc.CreateDocumentFragment(); newNode.InnerXml = partNnode.OuterXml; introNode.ParentNode.InsertAfter (newNode, introNode); partNnode.ParentNode.RemoveChild (partNnode); partNnode = xmlDoc.SelectSingleNode ("// part"); nodeList = xmlDoc.SelectNodes ("// section1"); \t \t \t 의 foreach (노드 목록에있는 XmlNode refrangeNode) {= newNode xmlDoc.CreateDocumentFragment(); newNode.InnerXml = refrangeNode.OuterXml; partNnode.AppendChild (newNode)} –