qxmlstreamwriter를 사용하여 xml의 여러 줄을 출력 파일에 주석으로 표시하려고합니다. 루프가 반복되어 중첩 된 구조를 반복하며 구조가 "isCommented"로 표시되면 "<! - -"(공백없이) 을 입력 한 다음 출력 XML 양식을 계속 작성해야합니다. 해당 구조가 끝나면 끝 주석을 삽입해야합니다 : "->". qxmlstreamwriter :: writeCharacters (QString) 메서드는 "<"과 같은 특수 문자를 선택하고 다시 해석하므로 충분하지 않습니다. 중첩 된 주석에 대한 사례를 이미 없앴습니다. 문제가되지 않습니다 (내부 루프와 외부 루프 모두 주석 처리되지 않을 것임) 대체 솔루션에 대한 아이디어가 있습니까? 다음은 내 코드의 예는 다음과 같습니다QXmlStreamWriter를 사용하여 여러 줄 주석
...
QXmlStreamWriter writer(&myFile)
for (int i = 0; i < bigStruct.size(); i++){
if (bigStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("BigStruct");
for (int j = 0; j < smallerStruct; j++){
if (smallerStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("SmallerStruct");
writer.writeTextElement("Stuff", "blah");
writer.writeTextElement("More Stuff", "blah blah blah");
writer.writeEndElement();
if (smallerStruct.at(i)->isCommented){
//end comment sequence
//insert "-->"
}
}
writer.writeEndElement();
if (bigStruct.at(i)->isCommented){
//endcomment sequence
//insert "-->"
}
}
...
예제 XML 출력이
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
<!--
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
-->
</BigStruct>
<!--
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
</BigStruct>
-->
것처럼 writeComment 보일 수 있습니다()하지만, 그것은 단지 하나의 선을 기록, 의견을 내 첫 번째 시도였다. 물론 필요한 경우 '\ n'문자로 큰 문자열을 만들 수 있지만 해당 블록을 만드는 데 필요한 코드는 내 루프의 프로그램 흐름을 벗어날 수 있습니다. 필자가 필요로하는 것은 writer.startComment() 및 writer.endComment() 등의 매끄러운 방법입니다. 다른 xml이 작성된 후 주석의 시작과 끝을 지정할 수 있습니다. 따라서 주석 내 qxmlstreamwriter를 사용하여 XML을 작성할 수 있습니다.
감사합니다.
답장을 보내 주셔서 감사합니다. writer.startComment()/writer.endComment() 기능을 지원하는 다른 qXML 파서 클래스를 알고 계십니까? – GatorGuy
아니요, 저는 모든 작가가 텍스트의 단일 엔티티에 주석을 처리한다고 생각합니다. 하나는 기본 장치에 을 쓰려고 할 수 있으며 xml 작성자가 알아 채지 못하도록하기를 바랍니다.하지만 그렇게되면 못생긴 해킹이 될 수 있습니다. 나는 임시 작가에게 가서 그 취급을 숨기기위한 좋은 convience 방법을 추가 할 것입니다. –