//.........这里部分代码省略.........
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
assert( itemElement );
itemElement->SetAttribute( "distance", "here" );
// Remove the "Look for Evil Dinosaurs!" item.
// It is 1 more sibling away. We ask the parent to remove
// a particular child.
itemElement = itemElement->NextSiblingElement();
todoElement->RemoveChild( itemElement );
itemElement = 0;
// --------------------------------------------------------
// What follows is an example of created elements and text
// nodes and adding them to the document.
// --------------------------------------------------------
// Add some meetings.
TiXmlElement item( "Item" );
item.SetAttribute( "priority", "1" );
item.SetAttribute( "distance", "far" );
TiXmlText text( "Talk to:" );
TiXmlElement meeting1( "Meeting" );
meeting1.SetAttribute( "where", "School" );
TiXmlElement meeting2( "Meeting" );
meeting2.SetAttribute( "where", "Lunch" );
TiXmlElement attendee1( "Attendee" );
attendee1.SetAttribute( "name", "Marple" );
attendee1.SetAttribute( "position", "teacher" );
TiXmlElement attendee2( "Attendee" );
attendee2.SetAttribute( "name", "Voel" );
attendee2.SetAttribute( "position", "counselor" );
// Assemble the nodes we've created:
meeting1.InsertEndChild( attendee1 );
meeting1.InsertEndChild( attendee2 );
item.InsertEndChild( text );
item.InsertEndChild( meeting1 );
item.InsertEndChild( meeting2 );
// And add the node to the existing list after the first child.
node = todoElement->FirstChild( "Item" );
assert( node );
itemElement = node->ToElement();
assert( itemElement );
todoElement->InsertAfterChild( itemElement, item );
printf( "\n** Demo doc processed: ** \n\n" );
//.........这里部分代码省略.........
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChild();
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
itemElement->SetAttribute( "distance", "here" );
// Remove the "Look for Evil Dinosours!" item.
// It is 1 more sibling away. We ask the parent to remove
// a particular child.
itemElement = itemElement->NextSiblingElement();
todoElement->RemoveChild( itemElement );
itemElement = 0;
// --------------------------------------------------------
// What follows is an example of created elements and text
// nodes and adding them to the document.
// --------------------------------------------------------
// Add some meetings.
TiXmlElement item( "Item" );
item.SetAttribute( "priority", "1" );
item.SetAttribute( "distance", "far" );
TiXmlText text;
text.SetValue( "Talk to:" );
TiXmlElement meeting1( "Meeting" );
meeting1.SetAttribute( "where", "School" );
TiXmlElement meeting2( "Meeting" );
meeting2.SetAttribute( "where", "Lunch" );
TiXmlElement attendee1( "Attendee" );
attendee1.SetAttribute( "name", "Marple" );
attendee1.SetAttribute( "position", "teacher" );
TiXmlElement attendee2( "Attendee" );
attendee2.SetAttribute( "name", "Voo" );
attendee2.SetAttribute( "position", "counselor" );
// Assemble the nodes we've created:
meeting1.InsertEndChild( attendee1 );
meeting1.InsertEndChild( attendee2 );
item.InsertEndChild( text );
item.InsertEndChild( meeting1 );
item.InsertEndChild( meeting2 );
// And add the node to the existing list after the first child.
node = todoElement->FirstChild( "Item" );
assert( node );
itemElement = node->ToElement();
assert( itemElement );
todoElement->InsertAfterChild( itemElement, item );
const char* TiXmlDocument::Parse
( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
{
ClearError();
// Parse away, at the document level. Since a document
// contains nothing but other tags, most of what happens
// here is skipping white space.
// sherm 100319: I changed this so that untagged top-level text is
// parsed as a Text node rather than a parsing error. CDATA text was
// already allowed at the top level so this seems more consistent.
if ( !p || !*p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// Note that, for a document, this needs to come
// before the while space skip, so that parsing
// starts from the pointer we are given.
location.Clear();
if ( prevData )
{
location.row = prevData->cursor.row;
location.col = prevData->cursor.col;
}
else
{
location.row = 0;
location.col = 0;
}
TiXmlParsingData data( p, TabSize(), location.row, location.col );
location = data.Cursor();
if ( encoding == TIXML_ENCODING_UNKNOWN )
{
// Check for the Microsoft UTF-8 lead bytes.
const unsigned char* pU = (const unsigned char*)p;
if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
&& *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
&& *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
{
encoding = TIXML_ENCODING_UTF8;
useMicrosoftBOM = true;
}
}
// Remember the start of white space in case we end up reading a text
// element in a "keep white space" mode.
const char* pWithWhiteSpace = p;
p = SkipWhiteSpace( p, encoding );
if ( !p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// sherm 100319: ignore all but the first Declaration
bool haveSeenDeclaration = false;
while ( p && *p )
{
TiXmlNode* node = 0;
if ( *p != '<' )
{ // sherm 100319: I added this case by stealing the code from
// Element parsing; see above comment.
// Take what we have, make a text element.
TiXmlText* textNode = new TiXmlText( "" );
if ( !textNode )
{
SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
return 0;
}
if ( TiXmlBase::IsWhiteSpaceCondensed() )
{
p = textNode->Parse( p, &data, encoding );
}
else
{
// Special case: we want to keep the white space
// so that leading spaces aren't removed.
p = textNode->Parse( pWithWhiteSpace, &data, encoding );
}
if ( !textNode->Blank() ) {
LinkEndChild( textNode );
node = textNode;
}
else
delete textNode;
}
else // We saw a '<', now identify what kind of tag it is.
{
TiXmlNode* node = Identify( p, encoding );
if ( node )
{
p = node->Parse( p, &data, encoding );
if (node->ToDeclaration()) {
if (haveSeenDeclaration) {
//.........这里部分代码省略.........
CSiteManagerItemData_Site* CSiteManager::GetSiteByPath(wxString sitePath)
{
wxChar c = sitePath[0];
if (c != '0' && c != '1')
{
wxMessageBox(_("Site path has to begin with 0 or 1."), _("Invalid site path"));
return 0;
}
sitePath = sitePath.Mid(1);
// We have to synchronize access to sitemanager.xml so that multiple processed don't write
// to the same file or one is reading while the other one writes.
CInterProcessMutex mutex(MUTEX_SITEMANAGER);
CXmlFile file;
TiXmlElement* pDocument = 0;
if (c == '0')
pDocument = file.Load(_T("sitemanager"));
else
{
const wxString& defaultsDir = wxGetApp().GetDefaultsDir();
if (defaultsDir == _T(""))
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
wxFileName name(defaultsDir, _T("fzdefaults.xml"));
pDocument = file.Load(name);
}
if (!pDocument)
{
wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR);
return 0;
}
TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
if (!pElement)
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
std::list<wxString> segments;
if (!UnescapeSitePath(sitePath, segments))
{
wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
return 0;
}
TiXmlElement* pChild = GetElementByPath(pElement, segments);
if (!pChild)
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
TiXmlElement* pBookmark;
if (!strcmp(pChild->Value(), "Bookmark"))
{
pBookmark = pChild;
pChild = pChild->Parent()->ToElement();
}
else
pBookmark = 0;
CSiteManagerItemData_Site* data = ReadServerElement(pChild);
if (!data)
{
wxMessageBox(_("Could not read server item."), _("Invalid site path"));
return 0;
}
if (pBookmark)
{
TiXmlHandle handle(pBookmark);
wxString localPath;
CServerPath remotePath;
TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text();
if (localDir)
localPath = ConvLocal(localDir->Value());
TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text();
if (remoteDir)
remotePath.SetSafePath(ConvLocal(remoteDir->Value()));
if (!localPath.empty() && !remotePath.IsEmpty())
{
data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false);
}
else
data->m_sync = false;
data->m_localDir = localPath;
data->m_remoteDir = remotePath;
}
//.........这里部分代码省略.........
请发表评论